EventLog Message Text Files

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • john s

    #1

    EventLog Message Text Files

    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++.
    What I have found in MSDN so far can be found here:
    http://msdn.microsoft.com/library/de...sage_files.asp
    and
    http://msdn.microsoft.com/library/de...er_section.asp


    Is it possible to do this in C#? I can't seem to find any howto's or
    examples for c#.
    My biggest hurdle doing this in C# is the " #define name ((type)0xnnnnnn nn)
    " 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).

    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
    misunderstandin g, or maybe point to some c# howto's or examples. I can't
    seem to find any.

    TIA,
    -John


  • Richard Grimes [MVP]

    #2
    Re: EventLog Message Text Files

    john s wrote:[color=blue]
    > 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++.[/color]

    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.
    [color=blue]
    > Is it possible to do this in C#? I can't seem to find any howto's or
    > examples for c#.[/color]

    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.
    [color=blue]
    > My biggest hurdle doing this in C# is the " #define name
    > ((type)0xnnnnnn nn) " 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).[/color]

    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 :-(
    [color=blue]
    > 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
    > misunderstandin g, or maybe point to some c# howto's or examples. I
    > can't
    > seem to find any.[/color]

    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
    (RegisterEventS ource, ReportEvent, UnregisterEvent Source) 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:


    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_MESSAGERESOU RCE.

    Richard
    --
    my email evpuneqt@zicf.b et is encrypted with ROT13 (www.rot13.org)


    Comment

    Working...