Message Resource DLL C# integration

H

Hamish

I'm looking to set up a .NET service (written in C#) that will write events
to the event log and use a message resource dll to provide localized message
text for the events.
The last time I set this up was some time ago (NT4 project circa 1998). I
was expecting the API to the event log to have improved.
Overall I'm not disappointed. It seems pretty straightforward.
The thing that surprises me is that I still seem to need to use mc.exe and
rc.exe to generate the resource only DLL and then I don't see a
straightforward way to integrate the generated header file (with the category
and message symbolic names) into the C# code for the service.
I kind of expected a new .NET way to do this (I guess my expectations are
pretty high because everything else I've looked at the framework seems to
pretty well cover).
I've set up a makefile to turn the message text file into a resource only
DLL and I'm looking into writing an MSBuild task to generate some C# enums
from the header file that rc.exe generates but I'm left with this lingering
feeling that I must be missing something, that there must be a more .NET
framework way to do this.
Can anyone point me at what I feel like I must be missing?
 
J

Jeroen Mostert

Hamish said:
I'm looking to set up a .NET service (written in C#) that will write events
to the event log and use a message resource dll to provide localized message
text for the events.

The framework uses a clever hack to get event log messaging to work without
the need for hardcoding strings in some DLL: all .NET event sources use
mscoree.dll as the event message file, and this has a resource block with
all possible message strings set to "%1" (i.e., just the first argument of a
formattable string) so it can pass anything it likes directly to the API.
The thing that surprises me is that I still seem to need to use mc.exe and
rc.exe to generate the resource only DLL and then I don't see a
straightforward way to integrate the generated header file (with the category
and message symbolic names) into the C# code for the service.

No, don't bother with all that nonsense, it's completely superfluous for
..NET applications.

For localization, .NET uses satellite assemblies and the ResourceManager
class. Look it up in the docs, it's pretty straightforward. When you want to
write to the event log, you can just write whatever string you want,
including localized strings you looked up.
 
H

Hamish

Thanks Jeroen.

That sound much more sensible. I think getting translators to work with a
resource file is going to be much easier than with the message text file
format.
This makes more sense. Remembering about MC.EXE and the way things used to
be probably just got in the way here.
 

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