Enable trace (How to debug Log4net while its not woking) When log4net cannot work)

Source: Internet
Author: User
Tags log4net

I wonder how many people have encountered the Log4net strike? Not in Zzk, and there are not many stackoverflow. The log4net self-report is not a reliable log component, but a highly efficient fail stop component. fail stop means to stop when the log fails, the operation is friendly. The following adjustment practices hope to help you.

Relying on Log4net all the year round, my brother was confused when he went on strike. There was always an error message. How did he adjust the information? I was confused twice. What should we do without it?

I used to know that the trace of. net is very strong and I didn't know it. I couldn't help it this time, but I don't know it. I can make the trace output to the text through several lines of configuration, as shown below:

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

It should be placed behind the system. web section. I don't know why I feel unreasonable.

If you replace the trace completely, it seems to be good, but you still like log4net, it is also very powerful. Adjust the log class described earlier, called loglog. Haha, that's right, the name is very interesting and appropriate, this is a class that records internal errors. The final call method is as follows:

private static void EmitOutLine(string message){try{#if NETCFConsole.WriteLine(message);//System.Diagnostics.Debug.WriteLine(message);#elseConsole.Out.WriteLine(message);Trace.WriteLine(message);#endif}catch{// Ignore exception, what else can we do? Not really a good idea to propagate back to the caller}}

We can see that it is put in the trace, so we only need to set up the log4net error with the trace above.

Enable the debug function in log4net. Set the manual code to log4net. Util. LogLog. InternalDebugging = true;

Of course, you can also add the following code in the deleetting section of the Configuration:

<Add key = "webpages: Version" value = "1.0.0.0"/>

The debug information will be output to the C: \ log4net.txt file.

Below are some of my error messages:

log4net:ERROR [RollingFileAppender] ErrorCode: GenericFailure. Unable to acquire lock on file E:\WebSites\CNBlogsZzk\src\ReleaseWeb\logs\Site.log. The process cannot access the file 'E:\WebSites\CNBlogsZzk\src\ReleaseWeb\logs\Site.log' because it is being used by another process.Quartz.Impl.StdSchedulerFactory: 2012-07-18 15:26:34 [1] INFO  Quartz.Impl.StdSchedulerFactory - Default Quartz.NET properties loaded from embedded resource filelog4net: Opening file for writing [E:\WebSites\CNBlogsZzk\src\ReleaseWeb\logs\Site.log] append [True]

 

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.