Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to read Application log and filter it based on source in ASP.NET?
    primarykey
    data
    text
    <p>In my application I want to read local system's application event log. Currently I am using the following code</p> <pre><code>public partial class AppLog : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { System.Diagnostics.EventLog logInfo = new System.Diagnostics.EventLog(); logInfo.Log = "Application"; logInfo.MachineName = "."; // Local machine string strImage = ""; // Icon for the event Response.Write("&lt;p&gt;There are " + logInfo.Entries.Count + " entries in the System event log.&lt;/p&gt;"); foreach (EventLogEntry entry in logInfo.Entries.Cast&lt;EventLogEntry&gt;().Reverse&lt;EventLogEntry&gt;()) { switch (entry.EntryType) { case EventLogEntryType.Warning: strImage = "images/icon_warning.PNG"; break; case EventLogEntryType.Error: strImage = "images/icon_error.PNG"; break; default: strImage = "images/icon_info.PNG"; break; } Response.Write("&lt;img src=\"" + strImage + "\"&gt;&amp;nbsp;|&amp;nbsp;"); Response.Write(entry.TimeGenerated.ToString() + "&amp;nbsp;|&amp;nbsp;"); Response.Write(entry.Message.ToString() + "&lt;br&gt;\r\n"); } } } } </code></pre> <p>I want to show only the log created by ASP.NET.I know I can filter it within the for-each loop.But this takes lot of time as it needs to iterate through the whole application log.Is there any way to to filter it before it goes into any iteration??</p> <p>====EDIT====</p> <p>I got a way to make query,don't know whether it really improves the performance</p> <pre><code> var result = (from EventLogEntry elog in logInfo.Entries where (elog.Source.ToString().Equals("ASP.NET 2.0.50727.0")) orderby elog.TimeGenerated descending select elog).ToList(); </code></pre> <p>and iterate through the result list.</p>
    singulars
    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.
 

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