Any Windows EventLog expert?

G

Guest

Hi

I have the code as below


if(!EventLog.SourceExists("XXXBspMode1")

EventLog.CreateEventSource("XXXBspMode1", "XXXMode1")


myLog = new EventLog()
myLog.Log = "XXXMode1"
myLog.Source = "XXXBspMode1"

myLog.WriteEntry("XXXBspMode1 started", EventLogEntryType.Information, 1, 0)


It looks simple rite? But when I try to run it, I will get the following error, but if I change the name of the source and the log, the error will not appear anymore, what is the problem, how can I solve the problem if I insist to use the XXX as the names? Thanks


Error: System.ArgumentException: The source 'MasBspMode1' is not registered in
og 'XXXMode1'. (It is registered in log 'Application'.) " The Source and Log pr
perties must be matched, or you may set Log to the empty string, and it will au
omatically be matched to the Source property
at System.Diagnostics.EventLog.WriteEvent(Int32 eventID, Int16 category, Eve
tLogEntryType type, String[] strings, Byte[] rawData
at System.Diagnostics.EventLog.WriteEntry(String message, EventLogEntryType
ype, Int32 eventID, Int16 category, Byte[] rawData
at System.Diagnostics.EventLog.WriteEntry(String message, EventLogEntryType
ype, Int32 eventID, Int16 category
at ConsoleApplication1.Class1.Main(String[] args) in d:\hkcciii\codes\build223\consoleapplication1\class1.cs:line 372
 
G

Guest

You might want to add this before setting up the mylo

myLog.SynchronizingObject = this;
 
G

Guest

What if I am NOT writing this is in a Window form?

The compiler keeps complaining 'cannot implicitly convert type "MyClass" to "System.ComponentModel.ISynchronizeInvoke"

I am using a normal class library class.....

Thank
SK
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top