Logging Patterns: ApplicationName
Brought to you by:
jvarszegi
Hey Guys,
I have a service application that accepts plugin
assemblies to be executed on a set time interval. The
service core and plugins all use NSpring for logging, but
when I use the {an} parameter in my logging pattern I
end up with an empty string.
Where does nspring get the application name value from?
Do I need to set this in my code?
Thanks for your help. You've done a wonderful job with
this package. It has helped me out a lot.
Logged In: YES
user_id=835109
Try this:
Logger l;
// ...
l.IsContextEnabled = true;
or
// This enables contexts for all future loggers created
Logger.IsContextEnabledByDefault = true;
Some of the tags are "context" related; the Context class has
some stuff attached to it that might bear reading about. I
know that I didn't make things very clear in the
documentation yet. Anyway, there is one Context for each
thread that makes calls to a logger; you can get access to it
by calling
Context c = Context.CurrentContext;
See, the static method is the only way you can get a handle
to one, and the retrieval of the one for this thread is done
under the covers to make everything easier to call. The
Context is basically a thread context; you can add properties
to it as you wish, and it also has some built-in stuff like
application name, system name, etc.
So to set the application name, you could do this:
Context.CurrentContext.ApplicationName = "abc";
And you'd also have to enable context logging. It's turned off
by default because there's some slight overhead in gathering
the information. Nothing to break the bank-- I just tried to
write everything for extreme speed. I didn't want to do extra
work that might not be wanted and needed by everybody.
When context logging is enabled, an immutable copy of the
current thread's Context object is added to each Event
object that's created during logging. This winds up getting
sent to output along with everything else. If no Context is on
an Event, though, any context-related tags will be silently
weeded out. I did this because I thought that it was
important that the logging code refrain from throwing errors
whenever possible.
There was a bug with making the immutable copy that
resulted in the {systemName} tag not getting filled in
properly, but that's fixed in the next minirelease. I think that
{an} should be okay. In any case, if you need to get
{systemName} or whatever fixed RIGHT AWAY, you can go
take a look at the code in the Context class; it's pretty short.
Please let me know if you still can't get it working.