问题
Is it possible to have multiple serilog loggers? Currently within my WebApi I can call Log.Information for example to log an information event, but is there a way that I can instead make different logs and call ExternalLog.Information or AuthenticationLog.Information from my controller? The purpose behind this is that my web api is currently working with multiple different databases for different yet interrelated projects, and I would like to store logs within each of these databases that pertain to them instead of needing to create an additional logging database if at all possible.
A better solution, that I figure is less likely is, can I map individual controllers to a log, so that any time that a specific controller calls log, it writes to the AuthenticationLog for example.
回答1:
I believe that the answer to this question is to use subloggers, rather than separate loggers. I have found that you can do .WriteTo.Logger
and filter further in there. I will accept this as the answer if nobody else has a better solution (and of course if I am able to get it to work). I need to be able to filter on the controller or action name, which at this time I have a second stack overflow question out to figure out how to get that data. Serilog with Asp.net Web Api not using enricher
来源:https://stackoverflow.com/questions/55376786/multiple-serilog-loggers