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
}