473,383 Members | 1,834 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,383 software developers and data experts.

How to use System.Diagnostics.EventLog ?

Hi,

I'm having some problems with the System.Diagnostics.EventLog class in .NET
2.0

I need to recreate an event message source inside a new log but the messages
keeps ending up in the old log?! I have simplified my code into this tiny
snippet:

EventLog.CreateEventSource("mySrc", "myLog1");
EventLog eventLog = new EventLog();
eventLog.Source = "mySrc";
eventLog.WriteEntry("myEntry1");
eventLog = null;

if (EventLog.SourceExists("mySrc"))
{
EventLog.DeleteEventSource("mySrc");
EventLog.CreateEventSource("mySrc", "myLog2");
}
eventLog = new EventLog();
eventLog.Source = "mySrc";
eventLog.WriteEntry("myEntry2");
eventLog = null;

The problem is that both "myEntry1" and "myEntry2" is written to "myLog1". I
had expected that "MyEntry2" would end up in "myLog2"? What's wrong with this
code?

sincerely,
martin
Apr 12 '06 #1
1 15954
Try this:
EventLog.CreateEventSource("mySrc", "myLog1");
EventLog eventLog = new EventLog();
eventLog.Source = "mySrc";
eventLog.WriteEntry("myEntry1");
eventLog = null;

if (EventLog.SourceExists("mySrc"))
{
EventLog.DeleteEventSource("mySrc");
EventLog.CreateEventSource("mySrc2", "myLog2");
}
eventLog = new EventLog();
eventLog.Source = "mySrc2";
eventLog.WriteEntry("myEntry2");
eventLog = null;\
--------------------
Thread-Topic: How to use System.Diagnostics.EventLog ?
thread-index: AcZeJP8eyH25GuLES4Kvc7UPTXpzIA==
X-WBNR-Posting-Host: 194.198.248.239
From: =?Utf-8?B?bWFydGlu?= <ma****@discussions.microsoft.com>
Subject: How to use System.Diagnostics.EventLog ?
Date: Wed, 12 Apr 2006 04:34:01 -0700
Lines: 33
Message-ID: <CA**********************************@microsoft.co m>
MIME-Version: 1.0
Content-Type: text/plain;
charset="Utf-8"
Content-Transfer-Encoding: 7bit
X-Newsreader: Microsoft CDO for Windows 2000
Content-Class: urn:content-classes:message
Importance: normal
Priority: normal
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.3790.1830
Newsgroups: microsoft.public.dotnet.languages.csharp
Path: TK2MSFTNGXA01.phx.gbl
Xref: TK2MSFTNGXA01.phx.gbl microsoft.public.dotnet.languages.csharp:397980
NNTP-Posting-Host: TK2MSFTNGXA01.phx.gbl 10.40.2.250
X-Tomcat-NG: microsoft.public.dotnet.languages.csharp

Hi,

I'm having some problems with the System.Diagnostics.EventLog class in .NET2.0

I need to recreate an event message source inside a new log but the messageskeeps ending up in the old log?! I have simplified my code into this tiny
snippet:

EventLog.CreateEventSource("mySrc", "myLog1");
EventLog eventLog = new EventLog();
eventLog.Source = "mySrc";
eventLog.WriteEntry("myEntry1");
eventLog = null;

if (EventLog.SourceExists("mySrc"))
{
EventLog.DeleteEventSource("mySrc");
EventLog.CreateEventSource("mySrc", "myLog2");
}
eventLog = new EventLog();
eventLog.Source = "mySrc";
eventLog.WriteEntry("myEntry2");
eventLog = null;

The problem is that both "myEntry1" and "myEntry2" is written to "myLog1". Ihad expected that "MyEntry2" would end up in "myLog2"? What's wrong with thiscode?

sincerely,
martin


{\rtf1\ansi\ansicpg1252\deff0\deflang1033{\fonttbl {\f0\fnil\fprq2\fcharset0
MS Sans Serif;}{\f1\fswiss\fcharset0 Arial;}}
{\*\generator Msftedit 5.41.21.2500;}\viewkind4\uc1\pard\f0\fs20 Cheers,\par
\par
johnKn [MS-SDK]\par
\par
\par
\par
-Please do not send email directly to this alias. This alias is for \par
newsgroup purposes only\par
\par
-This posting is provided "AS IS" with no warranties, and confers no
rights.\par
\par
-To provide additional feedback about your community experience please send
\par
e-mail to: sd*****@microsoft.com\par
\f1\par
}

May 1 '06 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Jeff Molby | last post by:
Does anyone know offhand how the EventLog acts on Win9x? Does it know to create text logs or does it just raise an exception? If anyone has any experience with this, I'd appreciate a brief...
0
by: Damien McCartney via .NET 247 | last post by:
Simon, did you ever find a resolution to this, I am having the sameproblem (with identical code and the reference exists in theregistry) but if i run the same code again the event willpopulate the...
1
by: spp | last post by:
How can I save the contents of System events into a new file and the clear this event log. I want to do programaticaly something like using event viewer with Save Log File As... and then Clear all...
5
by: David Conorozzo | last post by:
I am able to create new sources using CreateEventSource. I can call GetEventLogs, I can delete sources, I can see if sources exist BUT, as soon as I try a "WriteEntry", I get an exception: ...
1
by: SQLScott | last post by:
I am using the System.ServiceProcess methods to look at the status of several services. It will tell me if it is Stopped, Started, etc. But how do I tell if a service is Not Responding, or Hung?...
5
by: Ankit Aneja | last post by:
This is my problem. I am using Visual 2003, .Net framework 1.1 and the Application Block I configured the DAAB using the Enterprise Library Configuration now this is the error which is coming ...
0
by: jammendolia | last post by:
Hello all, I am having an intermittent exception occur when writing the the eventlog from a windows service application written in c#, running on a Win2k SP4 server. Here's the code: ...
8
by: =?Utf-8?B?U3RldmVU?= | last post by:
Under Vista, my program, when reading the system event log, will not show the message saying I don't have the right permission. All I wisht to do is read the event log and show the error messages....
0
by: celine1984 | last post by:
i have develop an application using visual studio 2005 and i encounter the following problem. An unhandled exception was generated during the execution of the current web request. Information...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.