I'm trying to use costome categories in my eventlog for a program I'm
writing.
But I have some problems with it, I cant get it to work. Checklist for
how I did this.
1. Created a resourceful.mc content is like this.
MessageId=0x1
Severity=Success
SymbolicName=INSTALL_CATEGORY
Language=English
Installation
..
MessageId=0x2
Severity=Success
SymbolicName=CORE_CATEGORY
Language=English
InetProdukt core
..
MessageId=0x3
Severity=Success
SymbolicName=IO_CATEGORY
Language=English
IO operation
..
MessageId=0x4
Severity=Success
SymbolicName=DATABASE_CATEGORY
Language=English
Database operation
..
MessageId=0x5
Severity=Success
SymbolicName=GARGE_CATEGORY
Language=English
Garage modul
..
MessageId=0x6
Severity=Success
SymbolicName=CARVAN_CATEGORY
Language=English
Carvan modul
..
MessageId=0x7
Severity=Success
SymbolicName=BOAT_CATEGORY
Language=English
Boat modul
..
MessageId=0x8
Severity=Success
SymbolicName=CAMPER_CATEGORY
Language=English
Camper modul
..
2. Then I compile the resource to a win32 native dll with this command
MC.exe -s msresource.mc
rc.exe msresource.res
link.exe /DLL /SUBSYSTEM:WINDOWS /NOENTRY /MACHINE:x86 msresource.Res
3. In my program I create a evensource like this:
int categoryCount = 8;
EventSourceCreationData sourceData;
if (!EventLog.SourceExists(Settings.Default.sourceNam e))
{
sourceData = new EventSourceCreationData("Inet","InetPrdukt");
if
(File.Exists(InetProdukt.Properties.Settings.Defau lt.mcResource))
{
sourceData.CategoryResourceFile = "mcresource.dll";
sourceData.CategoryCount = categoryCount;
}
EventLog.CreateEventSource(sourceData);
}
if (File.Exists("mcresource.dll"))
{
sourceData.CategoryResourceFile = "mcresource.dll";
sourceData.CategoryCount = 8;
}
I then checked the regedit to se if the path was correct
HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Servic es\Eventlog\Inet it
was ok
4. In my program I now tried to call the eventlog and set a category
in to ways, the first way I tried was like this:
EventLog eventLog = new EventLog("InetProdukt", ".","Inet");
eventLog.WriteEntry("bla", EventLogEntryType.Error, 5000, 1);
which would show the text "Installation" but I showed the text none
then I tried
eventLog.WriteEntry("bla", EventLogEntryType.Error, 5000, 0x1);
which would show the text "Installation" but I showed the text (1)
instead.
I'm using a Danish culture in my program. I have tried without this
same result
System.Threading.Thread.CurrentThread.CurrentCultu re = new
System.Globalization.CultureInfo("da-DK");
System.Threading.Thread.CurrentThread.CurrentUICul ture =
new System.Globalization.CultureInfo("da-DK");