码迷,mamicode.com
首页 > 其他好文 > 详细

利用log4添加log

时间:2017-03-31 15:37:06      阅读:354      评论:0      收藏:0      [点我收藏+]

标签:dom   configure   conf   文件   type   efi   value   obj   play   

應用log4net.dll

新建Global.asax,在cs文件中添加

 protected void Application_Start(object sender, EventArgs e)
        {
            #region system log init
            log4net.Config.XmlConfigurator.Configure(new System.IO.FileInfo(AppDomain.CurrentDomain.BaseDirectory + @"\Log.config"));
            #endregion
        }

 

添加Log.config文件

技术分享
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
    <configSections>
        <section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler, log4net" />
    </configSections>

    <log4net>
        <root>
            <level value="Error"/>
        </root>
        <logger name="FatalLog">
            <level value="Fatal"/>
            <appender-ref ref="RollingLogFileAppender"/>
        </logger>
        <logger name="ErrorLog">
            <level value="Error"/>
            <appender-ref ref="RollingLogFileAppender"/>
        </logger>
        <logger name="WarnLog">
            <level value="Warn"/>
            <appender-ref ref="RollingLogFileAppender"/>
        </logger>
        <logger name="DebugLog">
            <level value="Debug"/>
            <appender-ref ref="RollingLogFileAppender"/>
        </logger>
        <logger name="HTGInfoLog">
            <level value="Info"/>
            <appender-ref ref="RollingHTGFileAppender"/>
        </logger>
        <logger name="F4GInfoLog">
            <level value="Info"/>
            <appender-ref ref="RollingF4GFileAppender"/>
        </logger>
        <logger name="InfoLog">
            <level value="Info"/>
            <appender-ref ref="RollingLogFileAppender"/>
        </logger>
    <logger name="RuleEngineLog">
      <level value="Info"/>
      <appender-ref ref="RollingRuleEngineLogFileAppender"/>
    </logger>
        
        <appender name="RollingLogFileAppender" type="log4net.Appender.RollingFileAppender">
            <!--輸出路徑-->
            <file value="Log\"/>
            <param name="AppendToFile" value="true"/>
            <param name="MaxSizeRollBackups" value="1000"/>
            <param name="StaticLogFileName" value="false"/>
            <!--輸出按指定方式切換文件-->
            <param name="DatePattern" value="yyyyMMdd&quot;.log&quot;"/>
            <param name="RollingStyle" value="Composite"/><!--Date 按日期,Size 按大小-->
      <param name="maximumFileSize" value="10240KB" />
      <!--輸出LOG格式-->
            <lockingModel type="log4net.Appender.FileAppender+MinimalLock" />
            <layout type="log4net.Layout.PatternLayout">
                <param name="Header" value=""/>
                <param name="ConversionPattern" value="%n------------LogName:%c --------------------------------------------%nTimestamp: %d %nClient: %X%nThread:%thread%nLevel: %p%n%m %n-------------------------------------------------------------------------%n"/>
                <param name="Footer" value=""/>
            </layout>
            <!--輸出不同級別的LOG-->
            <!--<filter type="log4net.Filter.LevelRangeFilter">
        <param name="LevelMin" value="DEBUG"/>

        <param name="LevelMax" value="FATAL"/>

      </filter>-->
        </appender>

    <appender name="RollingRuleEngineLogFileAppender" type="log4net.Appender.RollingFileAppender">
      <!--Output path-->
      <file value="RuleEngineLog\"/>
      <param name="AppendToFile" value="true"/>
      <param name="MaxSizeRollBackups" value="1000"/>
      <param name="StaticLogFileName" value="false"/>
      <!--Output file as specified switch-->
      <param name="DatePattern" value="&quot;RuleEngineLog&quot;yyyyMMdd&quot;.log&quot;"/>
      <param name="RollingStyle" value="Composite"/>
      <param name="maximumFileSize" value="10240KB" />
      <!--LOG output format-->
      <lockingModel type="log4net.Appender.FileAppender+MinimalLock" />
      <layout type="log4net.Layout.PatternLayout">
        <param name="Header" value=""/>
        <param name="ConversionPattern" value="%n------------LogName:%c--------------------------------------------%n%m %n-----------------------------------------------------------------------------%n"/>
        <param name="Footer" value=""/>
      </layout>
    </appender>
    </log4net>
</configuration>
View Code

 

利用log4添加log

标签:dom   configure   conf   文件   type   efi   value   obj   play   

原文地址:http://www.cnblogs.com/whl4835349/p/6651503.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!