Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles / Languages / C#

Read Windows Security Log

2.00/5 (2 votes)
8 Jan 2010CPOL 18.1K  
This Tip will show how to read the Windows Event Log (Security Log) in your PC.You have to use these two libraries for collecting and access to Event Log.using System.Net;using System.Diagnostics;I wrote security Log reading code on button Click event. In below code, I read Windows...
This Tip will show how to read the Windows Event Log (Security Log) in your PC.

You have to use these two libraries for collecting and access to Event Log.
using System.Net;
using System.Diagnostics;


I wrote security Log reading code on button Click event. In below code, I read Windows Security log. OIRC-09 is my computer's name.You can change these things according to your's PC.

<code>private void button1_Click(object sender, EventArgs e)
        {
            EventLog EventLog1 = new EventLog("Security", "OIRC-09");
       </code>   
          
            foreach (System.Diagnostics.EventLogEntry entry in EventLog1.Entries)
            {
                if (entry.Category == "Logon/Logoff")
               ListBox2.Items.Add(entry.Message+"\n");
            }

        }


Here I read all Logon/Logoff messages and display it in a listbox. You can change the category of the event log and read it according to your necessacity.

Goto Windows Eventlog and read it carefully. Then you can get a proper idea about it.Path is ControlPanel>AdministrativeTools>EventViewer.

Remember reading the event log is not a difficult task.
meet you soon with eventlog writing code.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)