Background
In a new project where Serilog was chosen as the logger I automatically started passing around ILogger
interface. The code accesses Log.Logger
once and from then the classes that desire logging accept ILogger
via constructor injection.
I was challenged on this practice and the advice was to use the static methods on the Log
class, e.g. Serilog.Log.Debug(...)
. The argument is that there is a set;
on Log.Logger
so mocking is easy.
Looking at the api I can see that one of the benefits of passing ILogger
are the ForContext
methods.
I spent some time on the webs and in the Serilog's documentation but I could not find information about a canonical way to access the log throughout the application code.
Question
Is there a canonical, i.e. better-in-most-cases, way to access/pass around the Serilog logger and if there is, is it passing ILogger
or using the static api on the Serilog.Log
class?