Log4net does not run after configuration, no log output-php Tutorial

Source: Internet
Author: User
Log4net does not run after configuration, no log output

Lazy. in the new project, Nuget is used to download the log4net configuration file (that is, log4net without the version number. in detail, it indicates log4net xml), but after the configuration, log4net went on strike unexpectedly, and no error was reported. This configuration method uses an independent log4net. xml file for configuration.

Loading and use:


Var log4net_config = Path. Combine (Path. GetDirectoryName (GetType (). Assembly. Location), "log4net. xml ");

XmlConfigurator. Configure (newFileInfo (log4net_config ));

After checking the entire configuration, we found that the Nuget configuration file has some missing information:

The first is the file name, log4net. xml is not so easy to use, because log4net itself will also generate a file with the same name. if you are stubborn to use xml files, you need to work with the second point, make sure that the file in the output directory is indeed a configuration file. you are advised to change it to log4net. config is more appropriate;

The second is the file attribute in the project. to copy the file to the output directory, you must set it to always copy or newer copy. the generation operation should not be none. select the content;

After modifying the configuration file according to the preceding figure, log4net will survive after loading with the following code.


Var log4net_config = Path. Combine (Path. GetDirectoryName (GetType (). Assembly. Location), "log4net. config"); // here is diff.

XmlConfigurator. Configure (newFileInfo (log4net_config ));

For simplicity, you can also use the following in AssemblyInfo. cs:


// Note: it is added to the AssemblyInfo. cs file.

[Assembly: log4net. Config. XmlConfigurator (ConfigFile = "log4net. config", Watch = true)];

Well, log4net can play with us again.

Receive free Brothers IT education original linux O & M engineers video/detailed linux tutorial, details consulting official website Customer Service: http://www.lampbrother.net/linux/

Learn PHP, Linux, HTML5, UI, Android and other video tutorials (courseware + Notes + video )! Contact Q2430675018

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.