Log4net. dll configuration and application in the project

Source: Internet
Author: User
Tags log4net

1. First, reference log4net. dll in the project, and then add a configuration file log4net. config in the project.

<! -- Log Path -->
<! -- Log generation is appended to the file -->
<! -- Format of the log file name -->
<! -- The log duplication method is repeated by date. A log file is generated every day. -->



















2. add a sentence to AssemblyInfo. cs in the Properties folder of the project.

Of course, you must first add using log4net; and then add [assembly: XmlConfigurator (ConfigFile = "log4net. config", Watch = true)]

3. Start to use it where logs need to be recorded.

First, add using log4net;

Then define the global log variable private static readonly ILog Log = LogManager. GetLogger ("ApplePush"); // The name is consistent with the name in the configuration file.

Then, you can use the log where it can be used, for example

Log. Info ("record Log ");
Log. InfoFormat ("Push Service Startup .....");

Log. Warn ("warning ");

Log. Error ("Error message ");

And so on.

 

This is the most basic log4net usage and is useful to everyone!

Related Article

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.