Solved

Create custom eventlog

Posted on 2008-06-14
4
3,655 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
ID: 21810068
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
ID: 21815783
@jandromeda: Thanks but this gives me the exact same situation...
0
 
LVL 12

Author Comment

by:roverm
ID: 21837766
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
ID: 31467193
Thanks.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
What .NET website keeps me current? 9 57
Allow space in this pattern 2 48
Data is not showing from images 15 37
Angular JS Route 3 52
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, just open a new email message. In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
As a trusted technology advisor to your customers you are likely getting the daily question of, ‘should I put this in the cloud?’ As customer demands for cloud services increases, companies will see a shift from traditional buying patterns to new…

920 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

18 Experts available now in Live!

Get 1:1 Help Now