john s wrote:
I am trying to create a message text file for the Catagory field in
order to
map the catagory input number to a string text. I have found some
MSDN
information on this, but it appears to only be for C/C++.
Note that these .mc files are compiled by a special tool (message compiler,
mc.exe) that creates an unmanaged resource (.bin) that is added to the file
as a RT_MESSAGETABLE resource.
As the link mentions, when you install your application you register the
category and message resource files for your event log source by adding an
entry in the registry.
Is it possible to do this in C#? I can't seem to find any howto's or
examples for c#.
Sadly, no, not in v1.1 or v1.0. The EventLog class uses just one message
resource file which (put very politely, and not the language I would
normally use when talking about this class) is very lame.
My biggest hurdle doing this in C# is the " #define name
((type)0xnnnnnnnn) " part. I know that c# can do "#defines name" but
it can't take in a "type"
to my knowledge. Plus, I don't know what replaces the C++ headers in
C# (and I dont' know C++ in order to compare them).
Unfortunately you've misunderstood the docs. The data in the .mc files are a
special format understood *only* by the mc.exe tool. I wrote an article
about this for Visual C++ Developer that describes this, this article used
to be on MSDN library, but its not there anymore :-(
So, if anyone knows how to create a message text file for the EventLog
Catagory field in C#, please let me know what I am missing or
misunderstanding, or maybe point to some c# howto's or examples. I
can't
seem to find any.
If you want to use them now (and in the future) then create your own event
log category/message resource files and use a .NET Installer class to
register them when the app is installed. Then use the unmanaged functions
(RegisterEventSource, ReportEvent, UnregisterEventSource) to report the
event. On *no account* should you ever use EventLog to *write* event log
messages. This class is $%*#@ (I'm trying hard to be polite) Only use
EventLog to *read* event log messages.
The next version of the framework (Whidbey) is supposed to fix this issue,
for example:
http://longhorn.msdn.microsoft.com/l...ntsource2.aspx
Note that this will not allow you to create the message resource files in
C#.
The source for the mc.exe tool used to be available as part of the Platform
SDK (I've not checked in a while), but I would have thought that because
Microsoft are *so* in love with XML this would be a great use for it -
describe the message/category format strings as XML items and create a class
that reads the XML and compiles them to a RT_MESSAGERESOURCE.
Richard
--
my email
ev******@zicf.bet is encrypted with ROT13 (
www.rot13.org)