纽威
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

102 lines
4.4 KiB

  1. <?xml version="1.0" encoding="utf-8" ?>
  2. <configuration>
  3. <configSections>
  4. <section name="log4net" type="System.Configuration.IgnoreSectionHandler"/>
  5. </configSections>
  6. <appSettings>
  7. </appSettings>
  8. <log4net>
  9. <!--定义输出到文件中-->
  10. <appender name="LogFileAppender" type="log4net.Appender.RollingFileAppender">
  11. <lockingModel type="log4net.Appender.FileAppender+MinimalLock"/>
  12. <!--定义文件存放位置-->
  13. <file value="Logs/" />
  14. <datePattern value="yyyyMM&quot;\\log_&quot;yyyyMMdd&quot;.log&quot;"/>
  15. <appendToFile value="true" />
  16. <!--<rollingStyle value="Date" />-->
  17. <rollingStyle value="Composite" />
  18. <staticLogFileName value="false"/>
  19. <maxSizeRollBackups value="10"/>
  20. <maximumFileSize value="1MB"/>
  21. <layout type="log4net.Layout.PatternLayout">
  22. <!--每条日志末尾的文字说明-->
  23. <footer value="by XSX" />
  24. <!--输出格式-->
  25. <!--样例:2008-03-26 13:42:32,111 [10] INFO Log4NetDemo.MainClass [(null)] - info property:[%property{NDC}]-->
  26. <conversionPattern value="记录时间:%date 线程ID:[%thread] 日志级别:%-5level 类:%logger - 描述:%message%newline" />
  27. </layout>
  28. </appender>
  29. <!--定义输出到控制台命令行中-->
  30. <appender name="ConsoleAppender" type="log4net.Appender.ConsoleAppender">
  31. <layout type="log4net.Layout.PatternLayout">
  32. <conversionPattern value="%date [%thread] %-5level %logger [%property{NDC}] - %message%newline" />
  33. </layout>
  34. </appender>
  35. <!--定义输出到windows事件中-->
  36. <appender name="EventLogAppender" type="log4net.Appender.EventLogAppender">
  37. <layout type="log4net.Layout.PatternLayout">
  38. <conversionPattern value="%date [%thread] %-5level %logger [%property{NDC}] - %message%newline" />
  39. </layout>
  40. </appender>
  41. <!--定义输出到数据库中,这里举例输出到Access数据库中,数据库为C盘的log4net.mdb-->
  42. <appender name="AdoNetAppender_Access" type="log4net.Appender.AdoNetAppender">
  43. <connectionString value="Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:log4net.mdb" />
  44. <commandText value="INSERT INTO LogDetails ([LogDate],[Thread],[Level],[Logger],[Message]) VALUES (@logDate, @thread, @logLevel, @logger,@message)" />
  45. <!--定义各个参数-->
  46. <parameter>
  47. <parameterName value="@logDate" />
  48. <dbType value="String" />
  49. <size value="240" />
  50. <layout type="log4net.Layout.PatternLayout">
  51. <conversionPattern value="%date" />
  52. </layout>
  53. </parameter>
  54. <parameter>
  55. <parameterName value="@thread" />
  56. <dbType value="String" />
  57. <size value="240" />
  58. <layout type="log4net.Layout.PatternLayout">
  59. <conversionPattern value="%thread" />
  60. </layout>
  61. </parameter>
  62. <parameter>
  63. <parameterName value="@logLevel" />
  64. <dbType value="String" />
  65. <size value="240" />
  66. <layout type="log4net.Layout.PatternLayout">
  67. <conversionPattern value="%level" />
  68. </layout>
  69. </parameter>
  70. <parameter>
  71. <parameterName value="@logger" />
  72. <dbType value="String" />
  73. <size value="240" />
  74. <layout type="log4net.Layout.PatternLayout">
  75. <conversionPattern value="%logger" />
  76. </layout>
  77. </parameter>
  78. <parameter>
  79. <parameterName value="@message" />
  80. <dbType value="String" />
  81. <size value="240" />
  82. <layout type="log4net.Layout.PatternLayout">
  83. <conversionPattern value="%message" />
  84. </layout>
  85. </parameter>
  86. </appender>
  87. <!--定义日志的输出媒介,下面定义日志以四种方式输出。也可以下面的按照一种类型或其他类型输出。-->
  88. <root>
  89. <!--FATAL(致命错误)、ERROR(一般错误)、WARN(警告)、INFO(一般信息)、DEBUG(调试信息)、ALL(所有)-->
  90. <level value="DEBUG"/>
  91. <!--文件形式记录日志-->
  92. <appender-ref ref="LogFileAppender" />
  93. <!--控制台控制显示日志-->
  94. <appender-ref ref="ConsoleAppender" />
  95. <!--Windows事件日志
  96. <appender-ref ref="EventLogAppender" />-->
  97. <!-- 如果不启用相应的日志记录,可以通过这种方式注释掉
  98. <appender-ref ref="AdoNetAppender_Access" />
  99. -->
  100. </root>
  101. </log4net>
  102. </configuration>