log4net

assemblyinfo.cs

1
2
// 指定log4net的配置文件
[assembly: log4net.Config.XmlConfigurator(ConfigFile = "log4net.config", Watch = true)]

log4net.config

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
<?xml version="1.0" encoding="utf-8" ?>
<log4net>
  <root>
    <level value="ALL" />
    <appender-ref ref="ConsoleAppender" />
    <appender-ref ref="UdpAppender" />
    <appender-ref ref="RollingFileAppender" />
  </root>
  <appender name="ConsoleAppender" type="log4net.Appender.ConsoleAppender">
    <param name="Encoding" value="utf-8" />
    <layout type="log4net.Layout.PatternLayout">
      <conversionPattern value="%date{yyyy-MM-ddTHH:mm:ss.fffffffzzz} [%level]%newline%class.%method%newline%message%newline%exception%newline" />
    </layout>
  </appender>
  <appender name="UdpAppender" type="log4net.Appender.UdpAppender">
    <param name="Encoding" value="utf-8" />
    <localPort value="65535" />
    <remoteAddress value="127.0.0.1" />
    <remotePort value="65534" />
    <layout type="log4net.Layout.PatternLayout">
      <conversionPattern value="%date{yyyy-MM-ddTHH:mm:ss.fffffffzzz} [%level]%newline%class.%method%newline%message%newline%exception%newline" />
    </layout>
  </appender>
  <appender name="RollingFileAppender" type="log4net.Appender.RollingFileAppender">
    <param name="Encoding" value="utf-8" />
    <file value="logs/log" />
    <appendToFile value="true" />
    <rollingStyle value="Date" />
    <datePattern value="yyyyMMdd&quot;.txt&quot;"/>
    <lockingModel type="log4net.Appender.FileAppender+InterProcessLock" />
    <staticLogFileName value="false"/>
    <layout type="log4net.Layout.PatternLayout">
      <conversionPattern value="%date{yyyy-MM-ddTHH:mm:ss.fffffffzzz} [%level]%newline%class.%method%newline%message%newline%exception%newline" />
    </layout>
  </appender>
</log4net>