其他分享
首页 > 其他分享> > Log4net配置检查点

Log4net配置检查点

作者:互联网

  1. 有引用log4net.dll

  2. 有配置文件,Web.config或log4net.config

  3. 有section节

    <configuration xmlns="http://schemas.microsoft.com/.NetConfiguration/v2.0">
      <configSections>
        <section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler, log4net"/>
        <sectionGroup name="system.web">
            <section name="logService" type="OilDigital.CGGL.BLL.LogServiceSection, OilDigital.CGGL.BLL.Common" allowDefinition="MachineToApplication" restartOnExternalChanges="true"/>
    

    有system.web节,同时确保logProviderWithLog4Net中的enabled为true

      <system.web>
        <logService defaultProvider="logProviderWithLog4Net">
          <providers>
            <add name="logProviderWithLog4Net" type="OilDigital.CGGL.BLL.Log.LogProviderWithLog4Net,OilDigital.CGGL.BLL.Log" enabled="true" loggingUserName="false" loggerName="OperationLogger"/>
          </providers>
        </logService>
    

    有log4net节

    <log4net>
        <appender name="LogFileAppender" type="log4net.Appender.RollingFileAppender">
          <file value="Logs\\opeartions-"/>
          <appendToFile value="true"/>
          <rollingStyle value="Date"/>
          <datePattern value="yyyy-MM-dd&quot;.log&quot;"/>
          <maximumFileSize value="10MB"/>
          <staticLogFileName value="false"/>
          <lockingModel type="log4net.Appender.FileAppender+MinimalLock"/>
          <layout type="log4net.Layout.PatternLayout">
            <param name="ConversionPattern" value="%d [%t] %-5p %c %m%n"/>
          </layout>
        </appender>
        <logger name="OperationLogger">
          <level value="INFO"/>
          <appender-ref ref="LogFileAppender"/>
        </logger>
      </log4net>
    
  4. Global.asax的Application_Start方法中有初始化

                //初始化log4net对象
                log4net.Config.XmlConfigurator.Configure();
    

标签:Log4net,log4net,Web,配置文件,初始化,配置,检查点,config
来源: https://www.cnblogs.com/Sabre/p/15226058.html