I think is a bug, I check the source code can be found when calling CloseCurrentStream () function, m_Stream will be set to null, the error caused by FileLogTraceListener class said on MSDN is thread-safe, it seems not so, do you think what reason be?
Building engineering, the references need to quote ". Microsoft visual basic "
using System;
using System.Collections.Generic;
Using System. Linq;
Using System. The Text;
Using System. The Threading;
. Using Microsoft visual basic. Logging;
The namespace ConsoleApplication1
{
Class Program
{
The static void Main (string [] args)
{
Console. WriteLine (" start ");
Tracelog. StartTrace ();
For (int I=0; i <10; I++)
{
Thread backthread=new Thread (new ThreadStart (Worker));
Backthread. Start ();
}
}
Public static void Worker ()
{
While (true)
{
//the Console. WriteLine (" start ");
Tracelog. Trace (Tracelog. INFO, "test");
}
}
}
Public class Tracelog
{
Public static int the INFO=0;
Public static int the ERROR=1;
Public static FileLogTraceListener myListener;
//private static readonly object Lock=new object ();
Public static void StartTrace ()
{
Try
{
//lock (lock)
{
MyListener=new FileLogTraceListener (" myListener ");
MyListener. LogFileCreationSchedule=LogFileCreationScheduleOption. Daily;
MyListener. CustomLocation="log";
MyListener. BaseFileName="log";
MyListener. MaxFileSize=10 * 1024 * 1024;
Trace myListener. WriteLine (" start ");
MyListener. Flush ();
}
}
The catch (Exception e)
{
Console. WriteLine (" StartTrace error "+ e. oString ());
}
}
Public static void Trace (int type, string message)
{
Try
{
//lock (lock)
{
MyListener. WriteLine (message);
MyListener. Flush ();
}
}
The catch (Exception e)
{
Console. WriteLine (" Trace error message: "+ e. oString ());
}
}
}
}
CodePudding user response:
Their top, bosses for supportCodePudding user response:
After another wall bumps bumpsCodePudding user response:
Used FileLogTraceListener,When I use log4net
https://blog.csdn.net/hanjun0612/article/details/50924404