Click here to Skip to main content
15,892,674 members
Articles / Programming Languages / C#
Tip/Trick

Read Windows Security Log

Rate me:
Please Sign up or sign in to vote.
2.00/5 (2 votes)
8 Jan 2010CPOL 18K   2  
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)


Written By
Founder EdgeCat Infosys
Sri Lanka Sri Lanka
http://edgecat.weebly.com

Comments and Discussions

 
-- There are no messages in this forum --