log4Net 之 详细配置文件

 1 xml version="1.0" encoding="utf-8" ?>
 2 <configuration>
 3 <configSections>
 4 <section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler,log4net"/>
 5 configSections>
 6 <log4net>
 7 <root>
 8 
 9 
10 
11 <level value="ALL"/>
12 <appender-ref ref="rollingAppender"/>
13 root>
14 
15 
16 <appender name="rollingAppender" type="log4net.Appender.RollingFileAppender">
17 
18 
19 
20 
21 <file type="log4net.Util.PatternString" value="Logs/%date{yyyy-MM-dd}.log" />
22 
23 <appendToFile value="true"/>
24 
25 <lockingModel type="log4net.Appender.FileAppender+MinimalLock"/>
26 
27 <Encoding value="UTF-8" />
28 
29 <param name="StaticLogFileName" value="false" />
30 
31 
32 <datePattern value="yyyy-MM-dd" />
33 
34 
35 
36 <RollingStyle value="Size" />
37 
38 
39 
40 
41 <MaxSizeRollBackups value="2" />
42 
43 <maximumFileSize value="2MB"/>
44 
45 <staticLogFileName value="true" />
46 
47 
48 
49 
50 
51 
52 
53 
56 
57 
58 
62 
63 
64 <layout type="log4net.Layout.PatternLayout">
65 
66 
67 <conversionPattern value="%date [%t]%-5p %c - %m%n"/>
68 
69 layout> 
70 appender>
71 log4net>
72 configuration>
            XmlConfigurator.Configure(new FileInfo(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, @"Config\log4Net.config")));

            ILog m_log = LogManager.GetLogger(typeof(Program));

            m_log.Debug("这是一个Debug日志");
            m_log.Info("这是一个Info日志");
            m_log.Warn("这是一个Warn日志");
            m_log.Error("这是一个Error日志");
            m_log.Fatal("这是一个Fatal日志");

            Console.WriteLine("ok");
            Console.ReadLine();

 

你可能感兴趣的:(log4Net 之 详细配置文件)