Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mixing AddDebug() with a file based NLog configuration no longer works. #486

Closed
jcasale opened this issue Sep 29, 2019 · 6 comments
Closed

Comments

@jcasale
Copy link

jcasale commented Sep 29, 2019

Type: Question

NLog version: 4.6.5

NLog.Web/NLog.Web.AspNetCore version: 4.8.5

NLog.Extensions.Logging version: 1.5.4

Platform: .NET Core 2.2

Current NLog config

{
  "NLog": {
    "autoReload": false,
    "throwConfigExceptions": true,
    "extensions": {
      "NLog.Extensions.Logging": {
        "assembly": "NLog.Extensions.Logging"
      },
      "NLog.Web.AspNetCore": {
        "assembly": "NLog.Web.AspNetCore"
      }
    },
    "default-wrapper": {
      "type": "AsyncWrapper",
      "overflowAction": "Block"
    },
    "targets": {
      "file": {
        "type": "File",
        "fileName": "${basedir}/logs/web.log",
        "archiveFileName": "${basedir}/logs/web.{#}.log",
        "archiveEvery": "Day",
        "archiveNumbering": "DateAndSequence",
        "archiveDateFormat": "yyyy-MM-dd",
        "maxArchiveFiles": "31",
        "keepFileOpen": "true",
        "layout": "${longdate}|${event-properties:item=EventId_Id}|${logger}|${aspnet-TraceIdentifier}|${aspnet-mvc-controller}|${aspnet-mvc-action}|${aspnet-request-method}|${aspnet-user-identity}|${uppercase:${level}}|${message} ${exception:format=tostring}"
      } //,
      //"debugger": {
      //  "type": "Debugger",
      //  "layout": "${event-properties:item=EventId_Id}|${logger}|${aspnet-TraceIdentifier}|${aspnet-mvc-controller}|${aspnet-mvc-action}|${aspnet-request-method}|${aspnet-user-identity}|${uppercase:${level}}|${message} ${exception:format=tostring}"
      //}
    },
    "rules": [
      //{
      //  "logger": "*",
      //  "minLevel": "Trace",
      //  "writeTo": "Debugger"
      //},
      {
        "logger": "Microsoft.EntityFrameworkCore.ChangeTracking",
        "maxlevel": "Info",
        "final": true
      },
      {
        "logger": "Microsoft.EntityFrameworkCore.Database.Command",
        "writeTo": "file",
        "final": true,
        "filters": {
          "when": {
            "condition": "'${event-properties:item=EventId_Id}' == '20101'",
            "action": "Ignore"
          }
        }
      },
      {
        "logger": "*",
        "minLevel": "Trace",
        "writeTo": "file"
      }
    ]
  }
}

I recently noticed around the time I updated to NLog.Web/NLog.Web.AspNetCore 4.8.5 that the debug logger stopped working in addition to the NLog configuration. I could add an NLog debugger target, but I prefer the layout and configuration of the base provider. Is there anyway to restore this?

My WebHost configuration appears as follows:

public static IWebHostBuilder CreateWebHostBuilder(string[] args)
    => WebHost.CreateDefaultBuilder(args)
        .UseStartup<Startup>()
        .ConfigureLogging((context, logging) =>
        {
            logging.ClearProviders();
            logging.SetMinimumLevel(LogLevel.Trace);

            if (context.HostingEnvironment.IsDevelopment())
            {
                logging.AddDebug();
            }

            NLog.LogManager.Configuration = new NLogLoggingConfiguration(context.Configuration.GetSection("NLog"));
        })
        .UseNLog();
@snakefoot
Copy link
Contributor

@jcasale Does it work with NLog.Web.AspNetCore ver. 4.8.4 ?

@jcasale
Copy link
Author

jcasale commented Sep 30, 2019

Hi @snakefoot Yes I can confirm AddDebug logging is visible after reverting to 4.8.4.

@snakefoot
Copy link
Contributor

snakefoot commented Sep 30, 2019

Created PR #485 to fix this change in behavior.

Thank you for reporting this.

@304NotModified
Copy link
Member

304NotModified commented Sep 30, 2019

This will be fixed in 4.8.6. See #487

Currently working on the release

@304NotModified
Copy link
Member

@jcasale
Copy link
Author

jcasale commented Oct 1, 2019

Thanks for the quick update!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants