Solved

Create custom eventlog

Posted on 2008-06-14
4
3,656 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

NAS Cloud Backup Strategies

This article explains backup scenarios when using network storage. We review the so-called “3-2-1 strategy” and summarize the methods you can use to send NAS data to the cloud

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Error in JQuery 5 53
How to parse the string and split the sub directory names in asp.net 7 41
Winform Module - What is the ASP.Net equiv 2 22
Expression Evaluater 3 26
Article by: Ivo
C# And Nullable Types Since 2.0 C# has Nullable(T) Generic Structure. The idea behind is to allow value type objects to have null values just like reference types have. This concerns scenarios where not all data sources have values (like a databa…
Article by: Najam
Having new technologies does not mean they will completely replace old components.  Recently I had to create WCF that will be called by VB6 component.  Here I will describe what steps one should follow while doing so, please feel free to post any qu…
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

810 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