• log4net配置


    1.configuration配置

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

    2.Global.asax

            protected void Application_Start()
            {
                //加载log4配置
                log4net.Config.XmlConfigurator.Configure();
            }

    3.configuration的log4net节点

      <log4net>
        <logger name="wolflogInfo">
          <level value="Info" />
          <appender-ref ref="wolflogInfoFileAppender" />
        </logger>
        <logger name="wolflogError">
          <level value="Error" />
          <appender-ref ref="wolflogErrorFileAppender" />
        </logger>
        <logger name="wolflogALL">
          <level value="ALL" />
          <appender-ref ref="wolflogALLFileAppender" />
        </logger>
        <!-- 绑定使用的名称 -->  
        <appender name="wolflogInfoFileAppender" type="log4net.Appender.RollingFileAppender,log4net">
          <lockingModel type="log4net.Appender.FileAppender+MinimalLock" />
          <!--输出文件夹路径-->
          <param name="File" type="" value="App_Data/Log/Info/" />
          <param name="AppendToFile" value="true" />
          <param name="RollingStyle" value="Date" />
          <!--文件名称命名规则-->
          <param name="DatePattern" value="yyyyMMdd&quot;.txt&quot;" />
          <param name="StaticLogFileName" value="false" />
          <param name="MaxSizeRollBackups" value="62" />
          <layout type="log4net.Layout.PatternLayout,log4net">
            <!--输出头-->
            <param name="ConversionPattern" value="%n[%d] %c %n%m%n%n" />
          </layout>
        </appender>
        <appender name="wolflogErrorFileAppender" type="log4net.Appender.RollingFileAppender,log4net">
          <lockingModel type="log4net.Appender.FileAppender+MinimalLock" />
          <param name="File" type="" value="App_Data/Log/Error/" />
          <param name="AppendToFile" value="true" />
          <param name="RollingStyle" value="Date" />
          <param name="DatePattern" value="yyyyMMdd&quot;.txt&quot;" />
          <param name="StaticLogFileName" value="false" />
          <param name="MaxSizeRollBackups" value="62" />
          <layout type="log4net.Layout.PatternLayout,log4net">
            <param name="ConversionPattern" value="%n[%d] %c %n%m%n%n" />
          </layout>
        </appender>
        <appender name="wolflogALLFileAppender" type="log4net.Appender.RollingFileAppender,log4net">
          <lockingModel type="log4net.Appender.FileAppender+MinimalLock" />
          <param name="File" type="" value="App_Data/Log/ALL/" />
          <param name="AppendToFile" value="true" />
          <param name="RollingStyle" value="Date" />
          <param name="DatePattern" value="yyyyMMdd&quot;.txt&quot;" />
          <param name="StaticLogFileName" value="false" />
          <param name="MaxSizeRollBackups" value="62" />
          <layout type="log4net.Layout.PatternLayout,log4net">
            <param name="ConversionPattern" value="%n[%d] %c %n%m%n%n" />
          </layout>
        </appender>
      </log4net>

    4.调用

                ILog log = log4net.LogManager.GetLogger("wolflogInfo");
                log.Info("输出点东西Info");
                log.Error("输出点东西Error");
                ILog log1 = log4net.LogManager.GetLogger("wolflogError");
                log1.Info("输出点东西Info");
                log1.Error("输出点东西Error");
                ILog log2 = log4net.LogManager.GetLogger("wolflogALL");
                log2.Info("输出点东西Info");
                log2.Error("输出点东西Error");

    效果

     

  • 相关阅读:
    tp6.0使用EasyWeChat
    vue-admin-template使用
    tp6.0入门
    seo一些细节
    wordpress开发mac
    php加密
    小程序信息授权sessionKey失效问题
    app爬虫(python)开发——抓包工具的使用详细笔记
    app爬虫(python)开发——搭建开发环境(如何抓取app数据?)
    app爬虫(python)开发入门到实战个人笔记(目录)
  • 原文地址:https://www.cnblogs.com/lgxlsm/p/6253473.html
Copyright © 2020-2023  润新知