Skip to content
Csaba Nemes edited this page Feb 26, 2017 · 5 revisions

When using Serilog Adapter don't forget to reference the right Log class, the one within Tracer and not the original in Serilog.

using Tracer.Serilog;

Except when you configure the Logger where you still need to reference to the Serilog Log class

using SL = Serilog;        

SL.Log.Logger = new LoggerConfiguration().WriteTo.RollingFile(...)

The adapter will pass on all properties you define in the Log call, plus it will extend it with the following ones:

Property Name Description
MethodName Name of the method which contained the Log call
ClassName Name of the class which contained the method above

Of course all enrichers will still work as expected.

For trace enter and leave calls beside the above mentioned the logger also adds

Property Name Description
MethodName Name of the method which contained the Log call
CallingParameters A structure containing method call parameters with their values
TraceType A constant Enter or Leave representing the type of the trace entry
ReturnValue A structure containing method call return value and out parameters with their values
TimeTaken Running time for the method in milliseconds (only for leave)
StartTicks Ticks taken at the time of method entry (only for leave)
EndTicks Ticks taken at the time of method exit (only for leave)

ReturnValue will contain out parameters as well, the return value will have the key $return in the structure.

For trace enter and leave Adapter uses built-in message templates:

"Entered into {MethodName} ({CallingParameters})."

"Returned from {MethodName} ({ReturnValue}). Time taken: {TimeTaken:0.00} ms."

An example output template which makes use of the new properties:

outputTemplate: "{Timestamp:yyyy-MM-dd HH:mm:ss.fff} [{MachineName}][{ThreadId}][{Level}][{TraceType}]{ClassName}.{MethodName} {Message}{NewLine}{Exception}")

As of version 1.1 the destructuring of the trace enter and return parameters is also supported. Use the [Destructure] attribute to mark a type as target for destructuring. If the type you want to see in details is not in your codebase you can apply the [assembly: DestructureType(typeof(SomeType))] to the assembly level.

Clone this wiki locally