Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Well the solution I've come up with does use <a href="http://msdn.microsoft.com/en-us/library/system.diagnostics.eventlog.aspx" rel="nofollow noreferrer">System.Diagnostics.EventLog</a> and simply iterating over all events to filter for the ones I want. I guess this is straightforward, I just thought there would have been a more efficient interface for this. Any suggestions or improvements very welcome!</p> <p>I've created a method to return event log entries since a certain time: </p> <pre><code>/// &lt;summary&gt; /// Steps through each of the entries in the specified event log and returns any that were written /// after the given point in time. /// &lt;/summary&gt; /// &lt;param name="logName"&gt;The event log to inspect, eg "Application"&lt;/param&gt; /// &lt;param name="writtenSince"&gt;The point in time to return entries from&lt;/param&gt; /// &lt;param name="type"&gt;The type of entry to return, or null for all entry types&lt;/param&gt; /// &lt;returns&gt;A list of all entries of interest, which may be empty if there were none in the event log.&lt;/returns&gt; public List&lt;EventLogEntry&gt; GetEventLogEntriesSince(string logName, DateTime writtenSince, EventLogEntryType type) { List&lt;EventLogEntry&gt; results = new List&lt;EventLogEntry&gt;(); EventLog eventLog = new System.Diagnostics.EventLog(logName); foreach (EventLogEntry entry in eventLog.Entries) { if (entry.TimeWritten &gt; writtenSince &amp;&amp; (type==null || entry.EntryType == type)) results.Add(entry); } return results; } </code></pre> <p>In my test class I store a timestamp:</p> <pre><code>private DateTime whenLastEventLogEntryWritten; </code></pre> <p>and during test setup I set the timestamp to when the last event log entry was written: </p> <pre><code>EventLog eventLog = new EventLog("Application"); whenLastEventLogEntryWritten = eventLog.Entries.Count &gt; 0 ? eventLog.Entries[eventLog.Entries.Count - 1] : DateTime.Now; </code></pre> <p>At the end of my test I check that there were no event log errors: </p> <pre><code>Assert.IsEmpty(GetEventLogEntriesSince("Application", whenLastEventLogEntryWritten, EventLogEntryType.Error), "Application Event Log errors occurred during test execution."); </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload