c# - Separating application level logging and framework level logging in ASP.NET Core -
if add logging services container (in asp.net 5 rc1):
services.addsingleton<iloggerfactory>(); services.addsingleton(typeof(ilogger<>), typeof(logger<>)); //or services.addlogging();
then can use logger in app layer:
class myapplogicservice { public myapplogicservice(ilogger<myapplogicservice> logger) { logger.loginformation("hey"); } }
but in case logger.loginformation() events mix unimportant framework information events (according devs 10 per request!).
asp.net 5 documentation states:
it recommended perform application logging @ level of application , apis, not @ level of framework. framework has logging built in can enabled setting appropriate logging verbosity level.
what mean? mean using ilogger/iloggerfactory in client code (app logic) not recommended?
what elegant solution separate app level logging framework level logging? i'm using serilog , filtering contextsource, far elegant...
perform application logging @ level of application , apis, not @ level of framework think message here should not try , log every request details, because logged framework.
as of mixing framework log events , application log events - docs states:
when logger created, category name must provided. category name specifies source of logging events. convention string hierarchical, categories separated dot (.) characters. logging providers have filtering support leverages convention, making easier locate logging output of interest.
by default, when using injected ilogger<myapplogicservice>
, category name if full name of class (with namespace).
so, avoid cluttering log framework information, filter out noise, including categories match namespace. when using consolelogger
this:
loggerfactory.addconsole((cat, level) => cat.startswith("mynamespace."));
i suppose similar "using serilog , filtering contextsource".
Comments
Post a Comment