Is there anyway to enrich all Serilog output with the Method Name.
For Instance consider If I have the following;
Public Class MyClassName
Privat
It's possible to do this with an enricher by reflecting over the call stack, but very expensive to do so, so Serilog doesn't offer it.
Instead you can use something like:
Logger.Here().Information("Hello, world!");
and implement the Here()
method as an extension method on ILogger
:
Public Sub Here(ByVal logger as ILogger,
Optional memberName As String = Nothing)
Return logger.ForContext("MemberName", memberName)
End Sub