How to Read the applicatins logs from event viewer using vb.net or C# ?

Posted by Vikram_Rebel under Others on 1/28/2013 | Points: 10 | Views : 4194 | Status : [Member] | Replies : 2
Hi All,

This is regarding the application logs in event viewer.
When ever an application throws an error,the errors will be stored in Even viewer under "Application logs" section and this will be useful for rectifying the bug or error more efficiently.

And now my query is,Is there any way we can read these application logs from even viewer using vb.net or C# coding ? and these logs should be viewd in gridview,which can be updated dynamically

i have tried using the unix scripts but am not able to make it to the end.


Can anyone guide me to solve this query


Thanks,
Vikram




Responses

Posted by: Durgammahesh22 on: 1/30/2013 [Member] Starter | Points: 25

Up
0
Down
Hi,

You can read the event logs from your local sytem event viewer using the below code

 

using (EventLog systemLog = new EventLog("System")) // local System log (Reads all logs under system)
{
var entries = systemLog.Entries;
var lastEntry = entries[entries.Count - 1];
for (int i = 0; i < entries.Count;i++ )
Response.Write("message: " + entries[i].Message + "<br/>");
}


if you want to read application logs use like this
EventLog systemLog = new EventLog("Application")

Thanks,
Mahesh

Thanks,
Mahesh

Vikram_Rebel, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Vikram_Rebel on: 1/31/2013 [Member] Starter | Points: 25

Up
0
Down
Thanks for the reply..let me try in your way

Vikram_Rebel, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response