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 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