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!