Below Code will show how to Create/write into windows event viewer.
You can create your own Event viewer by specifying the name instead of "Application" in the program.
Only thing you have to remember is if you are writing into the server you should have admin rights to create event viewer in the systm.
//Need to add Below namespace to use Event viewer
static void Main(string args)
//Call function to write into event log
WriteEventLog EvtLog = new WriteEventLog();
private void LogErrorToEventLog()
string sSource = "Test"; ;
//Event log name where we are going to write
string sLog = "Application";
//String to write into the event log
string strErrToWrite = "Error Occured";
//Create event viewer if it does not exists
//Code to write Event into log
EventLog.WriteEntry(sSource, strErrToWrite, EventLogEntryType.Error, 234);
catch (Exception ex)
String strErr = "Error writing into event log:" + ex;
Please use code block for code.
I have formatted the code, but when i paste it here all formatting disappeard. I don't know is this the way you are expecting. Let me know if there is any other way to do it.
You need to add the code blocks. I have added it for you. Take a look at your resource now. If you Edit it, you will see the CODE blocks added.
Thank you i got it now..