event-context needs more documentation

3 messages Options
Embed this post
Permalink
Jamison

event-context needs more documentation

Reply Threaded More More options
Print post
Permalink
(This post was updated on )
I spent all morning looking for a way to add CustomerID, CustomerName, and etc to my logging. I finally stumbled on to this page. And realized event-context would handle what I needed.

My $0.02,
Jamie


Edit: I replied with possible text. Giving a little back. J
Jamison

Re: event-context needs more documentation

Reply Threaded More More options
Print post
Permalink
Remarks:

Use event-context to add runtime values to your log.

Example:

Within your application you must manually build the LogEventInfo object. This allows you to set the context variables.

dim theLog As NLog.Logger = NLog.LogManager.GetCurrentClassLogger()
Dim theEvent As NLog.LogEventInfo
theEvent = New NLog.LogEventInfo(LogLevel.Trace, "", "This is my log message")
theEvent.Context("CustomerID") = 12345
theEvent.Context("CustomerName") = "Acme, Inc."
theLog.Log(theEvent)

Now the event-context layout render gives you access to these values.

${event-context:item=CustomerID} -- produces "12345"
${event-context:item=CustomerName} -- produces "Acme, Inc."

andrecarlucci

Re: event-context needs more documentation

Reply Threaded More More options
Print post
Permalink
Hi Jamison,

That's exactly what I need. Thank you very much.

André