繁体   English   中英

如何按顺序写窗口事件日志

[英]How to write window event log by order

我正在尝试向 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 年开始以来的整秒数。这似乎是一个您无能为力的系统限制。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM