这是我的log4net配置文件

<?xml version="1.0" encoding="utf-8" ?>
<log4net debug="true">
  <appender name="ConsoleAppender" type="log4net.Appender.ConsoleAppender" >
    <filter type="log4net.Filter.LevelRangeFilter">
      <acceptOnMatch value="true" />
      <levelMin value="DEBUG" />
      <levelMax value="FATAL" />
    </filter>
    <layout type="log4net.Layout.PatternLayout">
      <conversionPattern value="%-5p %5rms [%-17.17t] %-22.22c{1} %-18.18M - %m%n" />
    </layout>
  </appender>

  <appender name="SmtpAppender" type="MySmtpClientSmtpAppender">
    <to value="[email protected]" />
    <from value="[email protected]" />
    <subject value="Game Server Monitoring Failed!" />
    <smtpHost value="smtp.x.com" />
    <username value="admin" />
    <password value="x" />
    <bufferSize value="256" />
    <lossy value="true" />
    <evaluator type="log4net.spi.LevelEvaluator">
      <threshold value="ERROR" />
    </evaluator>
    <layout type="log4net.Layout.PatternLayout">
      <conversionPattern value="%-5p %d [ThreadId: %t] Class:%c{1} Method:%M %nMESSAGE:%n%m%n%n" />
    </layout>
  </appender>

  <appender name="RollingLogFileAppender" type="log4net.Appender.RollingFileAppender">
    <file value="Logs\\wwwlog" />
    <appendToFile value="true" />
    <datePattern value="yyyyMMdd" />
    <maximumFileSize value="10MB" />
    <!--<rollingStyle value="Date" />-->
    <filter type="log4net.Filter.LevelRangeFilter">
      <acceptOnMatch value="true" />
      <levelMin value="INFO" />
      <levelMax value="FATAL" />
    </filter>
    <layout type="log4net.Layout.PatternLayout">
      <conversionPattern value="%date [%thread] %-5level %logger [%ndc] - %message%newline" />
    </layout>
  </appender>


  <root>
    <level value="DEBUG" />
    <appender-ref ref="ConsoleAppender" />
    <appender-ref ref="MySmtpAppender" />
    <appender-ref ref="RollingLogFileAppender" />
  </root>
</log4net>


我有什么想念的吗?是否有任何提示/建议来减少日志大小,同时保持清晰度和更好的转换模式?有什么有趣的技巧吗?

编辑:XMl文件没有进入代码块。有建议吗?

最佳答案

对于RollingLogFileAppender的一项建议是使用最小的lockingModel。使用此设置,日志文件不会被锁定,而是在每次写入时打开然后关闭。

<lockingModel type="log4net.Appender.FileAppender+MinimalLock" />

关于.net - 您的log4net配置中有什么?破解,优化,观察?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/619532/

10-09 08:41