jonwagner / EventSourceProxy

EventSourceProxy (ESP) is the easiest way to add scalable Event Tracing for Windows (ETW) logging to your .NET program
Other
97 stars 20 forks source link

Adding Logging Context using TraceParameterProvider and Message property of EventAttribute #13

Closed ailn closed 10 years ago

ailn commented 10 years ago

If you define an event method like this:

[Event(1, Message = "For loop iteration {0}")] void ForLoopIteration(int index);

and add additional context like this:

TraceParameterProvider.Default .ForAnything() .AddContext("arg2", () => "extra");

then in your logs you'll get: "For loop iteration extra''

If Message = "For loop iteration {0} with {1}" then you'll get: "For loop iteration extra with 1"

I guess additional parameters should be added to the end.

ailn commented 10 years ago

Btw, having configure additional data like in my previous message and having Message = "For loop iteration {0} with {1}", if you use SLAB's ObservableEventListener like this:

var listener1 = new ObservableEventListener(); listener1.EnableEvents(MyEvents.Log as EventSource, EventLevel.LogAlways, Keywords.All);

var subscr = listener1.LogToFlatFile(@"C:\work\Log.txt");

then you get something like this in the log file: Payload : [index : 1] [message : An error occurred when writing to a listener.]

If I use PerfView with the listener turned on I get: For loop iteration with 1

jonwagner commented 10 years ago

Yes, normally the context just shows up in the payload, but if you want to also add it to your message, you have to specify the additional replacement parameter. ESP will always add the context at the end after the last parameter on the method call.

As for the SLAB error, I'll have to debug that. Which nuget package contains the ObservableEventListener?

ailn commented 10 years ago

"you have to specify the additional replacement parameter" I did but in PerfView the order was mixed - the context was placed first in the message.

You can download the SLAB package from here: http://www.nuget.org/packages/EnterpriseLibrary.SemanticLogging/

ailn commented 10 years ago

BTW, does ESP always generate _Faulted and _Completed events for interfaces even if I decorate methods with EventAttribute?

jonwagner commented 10 years ago

See issue #11 and EventSourceImplementation.ImplementComplementMethods.

jonwagner commented 10 years ago

"I did but in PerfView the order was mixed - the context was placed first in the message."

OIC. Whoops. :)

jonwagner commented 10 years ago

I fixed the way mapped parameters are added. Now they are all added in the order they are specified in the method, with the context parameter being last.

In v2.0.2.

ailn commented 10 years ago

Thank you Jon!