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]