How do i write the percentage sign "%" to the event log?

  • Thread starter Thread starter K Viltersten
  • Start date Start date
K

K Viltersten

It seems that when i try to write a
percentage sign (%) into the event log
using WriteEntry method, the log believes
that i'm refering to some variable from
command line.

Is it a special character when logging?
I've tried to Google it a while but i saw
nobody giving a suggestion for a
resolution.

I've made a workaround by
WriteEntry(message.Replace("%","_"),...);
but it's not exactly a solution filling me
with pride.
 
No idea, but I presume you have tried both %% and \%?

I've tried "\%" and of course "\\%"
but it didn't work. Now that i've tried
the "%%" setup, i got DOUBLE percentage
signes! As one would expect, that is...

I'll go with this for now, unless someone
has a better idea. Thanks Peter!
 
No idea, but I presume you have tried both %% and \%?
Unfortunately, the docs for the unmanaged version of this API say:

Note that there is no way to log a string that contains %n,
where n is an integer value. This syntax is used in IPv6
addresses, so it is a problem to log an event message that
contains an IPv6 address. For example, if the message text
contains %1, the event viewer treats it as an insertion string.

http://msdn.microsoft.com/en-us/library/aa363679(VS.85).aspx

You didn't post a code example so we don't really know what you're trying
to write to the event log, but I would guess that you're running into the
same limitation in .NET, because .NET is using the underlying unmanaged
API.

Yes, that's what i went with - i put double percentage
signs in there. It feels like a kindergarten solution; more
a walk-around than a solution, really. Still, provided the
infromation above (thanks for the link), i guess i'm
already at the best position. Thanks!

(As for the code, i don't think it'll help us a lot. I only want
to log the string "%1%2%3".)
 

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

Back
Top