Thursday, 9 August 2012

Beginning .Net , C# programming : Read event logs and display with C# Examples and VB.Net Examples

You are able to reading event log from .Net application.
We are using "EventLog" class of "System.Diagnostics" namespace.
There are three categories of event log available Application, Security and System.

Here is example for this.
In this example we take one combobox, this combobox contains three values "Application", "Security" and "System". You can select any one category to read event log and display it's result in grid.

ASPX Code : 
        <asp:DropDownList runat="server" ID="cboEventLog">
            <asp:ListItem Text="Application" Value="Application"></asp:ListItem>
            <asp:ListItem Text="Security" Value="Security"></asp:ListItem>
            <asp:ListItem Text="System" Value="System"></asp:ListItem>
        </asp:DropDownList>
        <asp:Button runat="server" ID="btnGetEventLog" Text="Get Event Log" OnClick="btnGetEventLog_Click" />
        <br /><br />
        <asp:GridView ID="gvEventLog" runat="server" AllowPaging="true" PageSize="5" Width="100px" >
        </asp:GridView>

C# Examples :
        EventLog objEL = new EventLog();
        objEL.Source = cboEventLog.SelectedItem.Text;
        gvEventLog.DataSource = objEL.Entries;
        gvEventLog.DataBind();

VB.net Examples :
        Dim objEL As New EventLog()
        objEL.Source = cboEventLog.SelectedItem.Text
        gvEventLog.DataSource = objEL.Entries
        gvEventLog.DataBind()

Output :

(To view original image , click on image)

Here is an example of write or insert event log entry into windows event log. Click Here...

This type of C# Tips is very useful in day to day programming life.

Note : Give Us your valuable feedback in comments. Give your suggestions in this article so we can update our articles accordingly that.

1 comment:

  1. Thanks for all the information,it was very helpful and i really like that you are providing information on .net training ,being enrolled in .net freshers training with projects live training http://www.wiziq.com/course/57-fresher-training-projects i was looking for such .net fresher training to assist me and your information helped me a lot.Really like that you are providing such information . Thanks.

    ReplyDelete