static void Main(string[] args)
{
for(int i=0; i< 10; i++)
{
WriteSystemEventLog(i.ToString());
}
Console.ReadKey();
}
public static void WriteSystemEventLog(string msg, EventLogEntryType type = EventLogEntryType.Error)
{
EventLog myLog = null;
try
{
myLog = new EventLog();
myLog.Source = "My application";
myLog.WriteEntry(msg, type);
}
catch (Exception e)
{
Console.WriteLine("Error occured during write system event log, error message: " + e.Message);
}
if (myLog != null)
{
myLog.Dispose();
myLog = null;
}
}
打开事件日志,按日期排序,应为:
0 1 2 3 ...
实际值:
2 3 1 9 0 ...
加上一秒钟的睡眠可以解决这个问题,但还有其他办法吗?