EventLogQuery time format expected?

前端 未结 5 1003
孤独总比滥情好
孤独总比滥情好 2021-01-18 10:10

I\'m trying to use the EventLogQuery class to query the eventlog. I followed the example shown on http://msdn.microsoft.com/en-us/library/bb671200%28v=vs.90%29.aspx#Y0.

5条回答
  •  梦毁少年i
    2021-01-18 10:27

    Here's a C# example for initializing an EventLogQuery object that will only load event entries from the last day.

    var yesterday = DateTime.UtcNow.AddDays(-1);
    
    var yesterdayDtFormatStr = yesterday.ToString(
       "yyyy-MM-ddTHH:mm:ss.fffffff00K", 
       CultureInfo.InvariantCulture
    );
    
    var query = string.Format(
       "*[System/TimeCreated/@SystemTime >='{0}']", 
       yesterdayDtFormatStr
    );
    
    var elq = new EventLogQuery("Application", PathType.LogName, query);
    

提交回复
热议问题