serilog / serilog-extensions-logging

Serilog provider for Microsoft.Extensions.Logging
Apache License 2.0
309 stars 99 forks source link

How to get class + method information emitted to log #110

Closed sarchibald-mdsol closed 6 years ago

sarchibald-mdsol commented 6 years ago

I'm used to using NLog, but the company at which I am working is using SeriLog. NLog has a layout render ${callsite} which will emit the class name + method name in the log automagically.

I see that SeriLog has {SourceContext}, but that only seems to list the class name. Is there a way to get both the class name and the method name?

nblumhardt commented 6 years ago

Hi! We've been wary of the potential for performance issues and steered clear of this feature so far, but, it'd be interesting to try porting NLog's implementation to a Serilog ILogEventEnricher - perhaps something that could ship and be plugged in as an additional package? Let me know if you are keen to take a shot, happy to help out.

Cheers, Nick

nblumhardt commented 6 years ago

There's now a sample enricher published for this; please see https://github.com/serilog/serilog/issues/1084 and feel free to add any feedback over there. Thanks!