log4net 配置

xml

<configuration>
  <configSections>
    <section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler,log4net" />
  </configSections>

  <log4net>
    <!-- OFF, FATAL, ERROR, WARN, INFO, DEBUG, ALL -->
    <!-- Set root logger level to ERROR and its appenders -->
    <root>
      <level value="DEBUG" />
      <appender-ref ref="RollingFileTracer" />
    </root>
    <!-- Print only messages of level DEBUG or above in the packages -->
    <appender name="RollingFileTracer" type="log4net.Appender.RollingFileAppender,log4net">
      <lockingModel type="log4net.Appender.FileAppender+MinimalLock" />
      <param name="File" value="App_Data/Log/" />
      <param name="AppendToFile" value="true" />
      <param name="RollingStyle" value="Composite" />
      <param name="MaxSizeRollBackups" value="10" />
      <param name="MaximumFileSize" value="1MB" />
      <param name="DatePattern" value="&quot;Logs_&quot;yyyyMMdd&quot;.txt&quot;" />
      <param name="StaticLogFileName" value="false" />
      <layout type="log4net.Layout.PatternLayout,log4net">
        <param name="ConversionPattern" value="%d [%t] %-5p %c - %m%n" />
      </layout>
    </appender>
  </log4net>
</configuration>

 

 MvcApplication

log4net.Config.XmlConfigurator.Configure();

代码

private static ILog log = LogManager.GetLogger(typeof(ZSZDbContext));

 

posted @ 2019-05-10 22:58  一只桔子2233  阅读(105)  评论(0编辑  收藏  举报