開啓log4net內部調試

3種方法

  • debug屬性
  • log4net.Internal.Debug application setting
  • log4net.Util.LogLog.InternalDebugging屬性

debug屬性

log4net屬性及含義:

屬性 說明
debug 可選,值爲true/false,默認值是false。設置爲true時可以開啓log4net debugging。
update 可選,值爲 Merge/Overwrite,默認值是Merge。設置爲Overwrite時會重置該repository之前的配置。
threshold 可選,值爲該repository註冊過的日誌級別。默認值是ALL。設置該值後可以限制整個repository上的所有日誌消息的級別。

實例:

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

 <log4net debug="true">
    <root>
      <level value="ALL" />
      <appender-ref ref="xxx" />
    </root>
  </log4net>
</configuration>

log4net.Internal.Debug application setting

實例:

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
    <appSettings>
        <add key="log4net.Internal.Debug" value="true"/>
    </appSettings>
</configuration>

log4net.Util.LogLog.InternalDebugging屬性

將log4net.Util.LogLog.InternalDebugging屬性設置爲true後,內部調試信息會寫到控制檯和System.Diagnostics.Trace。
實例:

<configuration>
    ...
    
    <system.diagnostics>
        <trace autoflush="true">
            <listeners>
                <add 
                    name="textWriterTraceListener" 
                    type="System.Diagnostics.TextWriterTraceListener" 
                    initializeData="C:\tmp\log4net.txt" />
            </listeners>
        </trace>
    </system.diagnostics>

    ...
</configuration>

Referal

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章