我正在尝试向Windows事件日志中写入一些消息:
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 ...
增加1秒钟的睡眠可以解决此问题,但是还有其他方法吗?
可悲的是,系统事件日志中的事件仅被排序为一秒的分辨率,因为它们使用UNIX时间戳-自1970年初以来的秒数。这似乎是系统上的限制,您不能做太多。