Click here to Skip to main content
Licence 
First Posted 18 Sep 2007
Views 16,117
Bookmarked 12 times

Adding Event to Event Viewer

By | 18 Sep 2007 | Article
Code for adding events to the event viewer by C#

Navneet Sharma's Article for adding events to event viewer


Screenshot - coolimage1.jpg

Introduction

This article can be used to add/modify events to the event viewer using windows forms while developing from C# application in .Net 3.0 environments and I have used the assemblies and function to be added to the code for the smooth functionality.code has been inherited and implemented by me after a survey on the web and contains the items useful for creation of events using windows applications.

Background

This article can be used to add new events to the event viewer in windows events while developing with C# in windows application in .Net 3.0 environment.

Using the code

Copy this code to add events to the event viewer from windows forms while developing from C# application in .Net 3.0 environments and I have used the assemblies and function to be added to the code for the smooth functionality. Use the function named Create_Event() which can be called anywhere in your code(where you want) for e.g. Button1_Click event.

Copy the below code and paste it into your application.

//------------------------ ASSEMBLIES ---------------------------------------

using System.Diagnostics;

//------------------------ FUNCTION -----------------------------------------
private bool Create_Event(string strEventData, EventLogEntryType logentryTy)

{
bool bMsgType;
string strEventData;

try

{
strEventData="The matter to be added in the source event to be written.";

if (!(EventLog.SourceExists("Navneet", ".")))

{

EventSourceCreationData evscd = new EventSourceCreationData("Navneet", "Navneet");

EventLog.CreateEventSource(evscd);

}

EventLog ev = new EventLog("Navneet", ".", "Navneet");    // "." is used for locahost

ev.WriteEntry(strEventData, logentryTy, 10001);

ev.Close();

bMsgType = true;                //means the event has been added

}

catch (Exception ex)

{
bMsgType = false;              //means the event is not added

}

return bMsgType;
}

Language Used : C#

Platforms : Win XP Professional with SP 2, .Net 3.0

Points of Interest

Did you learn anything interesting/fun/annoying while writing the code? Did you do anything particularly clever or wild or zany?

History

This code has been implemented here for the first time in this post and if you want some modifications in it then mail me or suggest me the required improvements and I will do the required changes.

Please vote this article if this was useful to you.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here

About the Author

Navneet Codes

Web Developer

India India

Member

.Net Developer as well as Trainer

Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board. (secure sign-in)
 
Search this forum  
 FAQ
    Noise  Layout  Per page   
  Refresh
-- There are no messages in this forum --
Permalink | Advertise | Privacy | Mobile
Web02 | 2.5.120517.1 | Last Updated 18 Sep 2007
Article Copyright 2007 by Navneet Codes
Everything else Copyright © CodeProject, 1999-2012
Terms of Use
Layout: fixed | fluid