Log4net does not run after configuration, and there is no log output.

WBOY
Release: 2016-07-25 08:46:50
Original
1116 people have browsed it
I was lazy and used Nuget in the new project to download the configuration file of log4net(The one without the version number log4net.detail The instructions inside are log4net xml), but after setting it up, log4net unexpectedly stopped working without any error. This configuration method is to use an independent log4net.xml file for configuration.
Loading use:
code
var log4net_config=Path.Combine(Path.GetDirectoryName(GetType().Assembly.Location),"log4net.xml");
XmlConfigurator.Configure(newFileInfo(log4net_config));
After reviewing the entire configuration, I found that the configuration file from Nuget has some flaws:
One is The file name is log4net. You need to cooperate with the second point and ensure that the file in the output directory is indeed a configuration file. Personally, it is more appropriate to change it to log4net.config; The second is the file in the project Attributes, copy to the output directory need to be set to always copy or newer copy, the generation operation should not be None, please select the content; After modifying the configuration file as above, use the following code to load it, log4net
is alive again.
code
var log4net_config=Path.Combine(Path.GetDirectoryName(GetType().Assembly.Location),"log4net.config");// here is diff.XmlConfigurator.Configure (newFileInfo(log4net_config));
Of course, for simplicity, you can also use
:
code
in
AssemblyInfo.cs // Note:
is added in the
AssemblyInfo.cs
file[assembly:log4net.Config.XmlConfigurator(ConfigFile="log4net.config",Watch=true) ]; Well, just like that, log4net can play happily with us again.
Receive Brothers IT Education’s original Linux operation and maintenance engineer video/detailed Linux tutorial for free. For details, please contact the official website customer service: http://www.lampbrother.net/linux/
Learn PHP, Linux, HTML5, UI, Android and other video tutorials (courseware + notes + videos)! Contact Q2430675018



source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!