c# - Is .NET Core 2.0 logging broken? -


i can't seem trace level log information outputted after upgrading .net core 2.0 (+asp.net core 2.0).

in fact, if dotnet new webproject , add code below in startup configure, not trace or debug log messages, information , error messages twice. commenting out .addconsole()call output these (information , error) once - suggesting gets configured automatically console provider default. keep in mind, "file -> new" project experience, there nothing setup in program.cs logging or configuration @ - except i've added. seen things? or should register github issue it.

    public void configure(iapplicationbuilder app, ihostingenvironment env, iloggerfactory loggerfactory)     {         loggerfactory.addconsole(microsoft.extensions.logging.loglevel.trace);          if (env.isdevelopment())         {             app.usedeveloperexceptionpage();         }          app.run(async (context) =>         {             var logger = loggerfactory.createlogger("blah");             logger.logtrace("hello world : trace");             logger.logdebug("hello world : debug");             logger.loginformation("hello world : information");             logger.logerror("hello world : error");              await context.response.writeasync("hello world!");         });     } 

the way logging configured has changed little... recommended way configure loggers on addlogging method, such

services.addlogging(builder => {     builder.addconfiguration(configuration.getsection("logging"))         .addconsole()         .adddebug(); }); 

and have appsettings.json

{   "applicationinsights": {     "instrumentationkey": ""   },   "logging": {     "includescopes": false,     "console": {       "loglevel": {         "default": "warning",         "system": "information",         "microsoft": "information"        }     }   } } 

please note structure of appsettings.json changed used in .net core 1.x , logging entry in appsettings.json has logger provider names in it, allows configure logging levels per logging provider.

previously, entry in appsettings.json applicable console logger.

alternatively, logging can moved within webhostbuilder instead.

public static void main() {     var host = new webhostbuilder()         .usekestrel()         .usecontentroot(directory.getcurrentdirectory())         .configureappconfiguration((hostingcontext, config) =>         {             var env = hostingcontext.hostingenvironment;              config.addjsonfile("appsettings.json", optional: true, reloadonchange: true)                 .addjsonfile($"appsettings.{env.environmentname}.json", optional: true)                 .addjsonfile("hosting.json", optional: false)                 .addenvironmentvariables();         })         .configurelogging((webhostcontext, builder) => {             builder.addconfiguration(webhostcontext.configuration.getsection("logging"))             .addconsole()             .adddebug();         })         .useiisintegration()         .usestartup<startup>()         .useapplicationinsights()         .build();      host.run(); } 

update

in case 1 doesn't want use appsettings.json, 1 can register filters in code too.

services.addlogging(builder => {     builder.addconfiguration(configuration.getsection("logging"))         // filter providers         .addfilter("system", loglevel.debug)         // debug logger, using provider type or it's alias         .addfilter("debug", "system", loglevel.information)         // console logger provider type         .addfilter<debugloggerprovider>("system", loglevel.error)         .addconsole()         .adddebug(); }); 

Comments

Popular posts from this blog

ubuntu - PHP script to find files of certain extensions in a directory, returns populated array when run in browser, but empty array when run from terminal -

php - How can i create a user dashboard -

javascript - How to detect toggling of the fullscreen-toolbar in jQuery Mobile? -