c# - Logging in .NET with Serilog -
in application, users can run multiple jobs, each of operations on files , output file. in course of these operations need log errors run in multiple log files, 1 per job.
i know can set different sinks (i.e. multiple log files) in code serilog, i'm injecting service performing operations , logging there. service injected api controller calls service methods.
what i'm not sure here how handle calling serilog logging methods within controller, since need logging in there while still using same sink i'm using in service. example, 1 job there 1 log file shared between controller , service duration of job.
if expose interface method like
public void setlogfile(string filename) { log.logger = new loggerconfiguration() .writeto.rollingfile(pathformat: _hostingenvironment.contentrootpath + "/" + filename + ".log", outputtemplate: "{timestamp:yyyy-mm-dd hh:mm:ss.fff zzz} {sourcecontext} [{level}] {message}{newline}{exception}") .createlogger(); }
in service call controller or wherever, configuration global , usable in controller if inject ilogger in there?
any tips appreciated!
Comments
Post a Comment