log4net 列印調試資訊到 Visval Studio 調試輸出視窗; output debug infomation to output window

來源:互聯網
上載者:User
1.Web.config:

<appSettings>      <add key="log4net.Internal.Debug" value="true"/></appSettings>

  

2.log4net_config_file.xml

<appender name="DebugAppender" type="log4net.Appender.DebugAppender, log4net" >      <layout type="log4net.Layout.PatternLayout">        <param name="ConversionPattern" value="%d [%t] %-5p %c [%x] - %m%n" />      </layout>    </appender>...  <logger name="logger_name" debug="false">        <level value="Debug" />        <appender-ref ref="RollingLogFileAppender" />        <appender-ref ref="DebugAppender" />    </logger>

 

3. cs:

private static readonly ILog logger = LogManager.GetLogger("logger_name");//...if (logger.IsDebugEnabled) {                logger.Debug("請求時返回資料: " + some infomation);            }

  

How do I enable log4net innteral debugging?

There are 2 different ways to enable internal debugging in log4net. These are listed below. The preferred method is to specify the log4net.Internal.Debug option in the application's config file.

  • Internal debugging can also be enabled by setting a value in the application's configuration file (not the log4net configuration file, unless the log4net config data is embedded in the application's config file). The log4net.Internal.Debug application setting must be set to the value true. For example:

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

    This setting is read immediately on startup an will cause all internal debugging messages to be emitted.

  • To enable log4net's internal debug programmatically you need to set the log4net.Util.LogLog.InternalDebugging property to true. Obviously the sooner this is set the more debug will be produced.

Internal debugging messages are written to the console and to the System.Diagnostics.Trace system. If the application does not have a console the messages logged there will be lost. Note that an application can redirect the console stream by setting the System.Console.Out. The Trace system will by default send the message to an attached debugger (where the messages will appear in the output window). If the process does not have a debugger attached then the messages are sent to the system debugger. A utility like DebugView from http://www.sysinternals.com may be used to capture these messages.

As log4net internal debug messages are written to the System.Diagnostics.Trace system it is possible to redirect those messages to a local file. You can define a trace listener by adding the following to your application's .config file:

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

Make sure that the process running your application has permission to write to this file.

from:http://logging.apache.org/log4net/release/faq.html

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.