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

Nlog does not log Trace events in asp.net core 2 #238

Closed
xumix opened this issue Dec 11, 2017 · 13 comments
Closed

Nlog does not log Trace events in asp.net core 2 #238

xumix opened this issue Dec 11, 2017 · 13 comments
Labels

Comments

@xumix
Copy link

xumix commented Dec 11, 2017

NLog.Web.AspNetCore 4.5.0-beta04, asp.net core 2.0.3

The code: https://gist.github.com/xumix/3cfb305dfd0f3cb743f9f25908212e4e
I add in Startup.cs

public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
        {
            loggerFactory.AddConsole();
            loggerFactory.AddDebug();
            app.UseMiddleware<RequestLoggingMiddleware>();

            LayoutRenderer.Register("basedir", (logEvent) => env.ContentRootPath);
}
<nlog xmlns="http://www.nlog-project.org/schemas/NLog.xsd"
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      autoReload="true"
      internalLogLevel="info"
      internalLogFile="c:\temp\internal-nlog.txt">
  <!-- the targets to write to -->
  <targets>
    <target xsi:type="File" name="request-file" fileName="${basedir}/logs/request-${shortdate}.log"
            layout="${longdate}|${uppercase:${level}}|${logger}|${message}" />
  </targets>

 <rules>
    <logger name="*RequestLoggingMiddleware*" writeTo="request-file" final="true" />
  </rules>
</nlog>

If I change logger.LogInformation(requestLog); to logger.LogTrace(requestLog); then no logging occurs, even if I add minlevel="Trace"

@304NotModified
Copy link
Member

Use configureLogging and

builder.SetMinimumLevel()

PS on mobile now

@snakefoot
Copy link
Contributor

snakefoot commented Dec 11, 2017

Program.cs should be extended to include ConfigureLogging(l => l.SetMinimumLevel(LogLevel.Trace)) :

using Microsoft.Extensions.Logging;  // Required for calling extension method SetMinimumLevel

public static IWebHost BuildWebHost(string[] args) =>
            WebHost.CreateDefaultBuilder(args)
            .UseStartup<Startup>()
            .ConfigureLogging(l => l.SetMinimumLevel(LogLevel.Trace))
            .UseNLog()
            .Build();

See also https://docs.microsoft.com/en-us/aspnet/core/fundamentals/logging/?tabs=aspnetcore2x

@304NotModified
Copy link
Member

Program.cs should be extended to include ConfigureLogging(l => l.SetMinimumLevel(LogLevel.Trace)) :

This works with AddNLog (ASP.NET Core 1 style), but not with UseNLog (see ##234) - any idea?

@snakefoot
Copy link
Contributor

snakefoot commented Dec 11, 2017

This works with AddNLog, but not with UseNLog - any idea?

No idea. Just copy pasting random information :). Not developing ASP NET Applications.

@304NotModified
Copy link
Member

No idea. Just copy pasting random information :). Not developing ASP NET Applications.

Hopefully that doesn't mean WinForms ;)

@xumix
Copy link
Author

xumix commented Dec 12, 2017

@304NotModified @snakefoot thanks!

@snakefoot
Copy link
Contributor

Hopefully that doesn't mean WinForms ;)

No just backend developer on various data-processing engines.

@snakefoot
Copy link
Contributor

@xumix Maybe my rant at #234 might be useful. Seems asp.net core 2 will choose appsettings.json LogLevel-config when available.

@georgiosd
Copy link

@snakefoot you sir, are awesome. I would have never guessed that in a million years. Thank you.

Removing config from appsettings.json and setting minimum level worked for me.

@paulostradioti
Copy link

Hi guys,

It looks like this is still a problem in .NET Core 3.1.
Any advice, please?

@snakefoot
Copy link
Contributor

snakefoot commented Feb 11, 2020 via email

@304NotModified
Copy link
Member

304NotModified commented Feb 12, 2020

@paulostradioti checked https://github.com/NLog/NLog.Web/wiki/Missing-trace%5Cdebug-logs-in-ASP.NET-Core-3%3F ?

And indeed, if it still an issue, please open a new github issue, thanks!

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

5 participants