I have the following code to set the username for
logging.
Context.CurrentContext.UserName =
m_strLogContextUser;
I have this token in my logging pattern.
{userName}
The userName is not being logged.
Am I missing a step, or is this a bug?
Thanks,
Bobio
Logged In: YES
user_id=835109
You have to set the IsContextEnabled property of the logger
in order for it to add the context information to each logged
event. This is enabled by default, as there's a little bit of
overhead involved (nothing serious, believe me) and it also
leads to more verbose XML at the default settings.
If that doesn't work, please post your code: construction and
configuration of the logger, and a sample call to Log().
Thanks. -Jeff
Logged In: YES
user_id=835109
Bob, sorry-- make that "is NOT enabled" by default.
Here's the deal: I thought about putting a flag on the current
context itself, indicating whether or not to always log context
information for the thread, no matter what logger. But this
would enable checking a LocalStoreDataSlot or something
similar each time an event was logged, and I didn't want the
extra overhead. Now I'm think that
an 'IsContextEnabledByDefault' static property of Logger may
be in order, so you could set it and forget it for the rest of
your application's run. I will think about it.
Jeff
Logged In: YES
user_id=835109
Bob, I found it-- it is a bug, as you were thinking. This
should be the only Context-related item not working. The
issue is that when an immutable copy of the context is
created and added to the event, the user name isn't copied
over (everything else looks like it's successfully copied over, I
just forgot to put in that single line). I'm sorry for the error.
The code will be updated tonight (I can't do it from work). I
will let you know. -Jeff
Logged In: YES
user_id=852225
Cool, Thanks for the fast response.
Bobio