Solved

Create custom eventlog

Posted on 2008-06-14
4
3,654 Views
Last Modified: 2010-04-21
Hi all,

I am creating an custom eventlog using the code below.
The eventlog and source will be created fine but something strange happens when I write to the log:

This customlog and the Application log keep track of the same entries! So whenever I write an entry to my custom log it will also show up in the application log. And, whenever any application logs to the application log, it will also show up in my custom log.

I have never seen this before. I used this piece of code many times but always on a Windows XP development machine.
Now I am developing on a Windows Server 2003 machine...

Does anybody know how to solve this issue so that the logs are not interconnected anymore?

Thanks!

D'Mzz!
RoverM

EventLog _eLog;

string sourceName = "MyService v2.1";

string logName = "MyService";
 

if (!EventLog.SourceExists(sourceName))

{

   EventSourceCreationData data = new EventSourceCreationData(sourceName, logName);

   EventLog.CreateEventSource(data);

}
 

EventLog[] logs = EventLog.GetEventLogs();

if (logs != null)

{

   foreach (EventLog log in logs)

   {

      if (log.Log == logName)

      {

         if (log.OverflowAction != OverflowAction.OverwriteAsNeeded)

            log.ModifyOverflowPolicy(OverflowAction.OverwriteAsNeeded, 1);

         this._eLog = log;

         this._eLog.Source = sourceName;

         break;

      }

   }

}

Open in new window

0
Comment
Question by:roverm
  • 3
4 Comments
 
LVL 12

Accepted Solution

by:
jandromeda earned 500 total points
Comment Utility
Try this code.
string logName = "TestLog";

			string logSource = "TestSource";

			EventLog myLog = null;

			

			if (!EventLog.Exists(logName))

			{

				EventLog.CreateEventSource(logSource, logName);

			}

			

			EventLog[] logs = EventLog.GetEventLogs();

			

			foreach (EventLog log in logs)

			{

				if (log.Log == logName)

				{

					myLog = log;

					myLog.Source = logSource;

					myLog.WriteEntry("TestMessage2");

					break;

				}

			}

Open in new window

0
 
LVL 12

Author Comment

by:roverm
Comment Utility
@jandromeda: Thanks but this gives me the exact same situation...
0
 
LVL 12

Author Comment

by:roverm
Comment Utility
Ok: I have tried my own code on another computer (same os) and on this one it works just fine.

Closing it...
0
 
LVL 12

Author Closing Comment

by:roverm
Comment Utility
Thanks.
0

Featured Post

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

Suggested Solutions

In order to hide the "ugly" records selectors (triangles) in the rowheaders, here are some suggestions. Microsoft doesn't have a direct method/property to do it. You can only hide the rowheader column. First solution, the easy way The first sol…
Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

772 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now