Log4net prints debugging information to the visval studio debugging output window; Output debug infomation to output window

Source: Internet
Author: User
Tags log4net
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] %-5 p % C [% x]-% m % N "/> </Layout> </appender>... <logger name = "logger_name" DEBUG = "false"> <level value = "debug"/> <appender-ref = "rollinglogfileappender"/> <appender-ref =" debugappender "/> </logger>

3. CS:

Private Static readonly ilog logger = logmanager. getlogger ("logger_name ");//... if (logger. isdebugenabled) {logger. debug ("returned data upon request:" + 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 specifyLog4net. Internal. DebugOption 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:

     
         
         
          
           
          
         

    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 . obviusly 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 toSystem. Diagnostics. TraceSystem 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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.