Solved

Create custom eventlog

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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Summary: Persistence is the capability of an application to store the state of objects and recover it when necessary. This article compares the two common types of serialization in aspects of data access, readability, and runtime cost. A ready-to…
This article introduced a TextBox that supports transparent background.   Introduction TextBox is the most widely used control component in GUI design. Most GUI controls do not support transparent background and more or less do not have the…
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…

840 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