Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ASPNet5 SeriLog LogDebug not working

I have an ASP.Net5 web application with serilog configured. In my home controller I print a Warning, Error, Verbose and Debug message, however in my console only Warning, Error and Verbose messages appear. The debug message is missing My configuration is:

public class Startup
{
  public Startup(IHostingEnvironment env)
  {

      Log.Logger = new LoggerConfiguration()
      .MinimumLevel.Verbose()
      .WriteTo.ColoredConsole()
      .WriteTo.RollingFile(Path.Combine(env.WebRootPath, "log-{Date}.txt"))
      .CreateLogger();
  }


  public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
  {
      loggerFactory.AddSerilog();
  }

}

I consume the logger via dependency injection, see below:

public class HomeController : Controller
{
    private readonly ILogger _logger;
    public HomeController(ILogger<HomeController> logger)
    {
      _logger = logger;
    }

    public async Task<IActionResult> Index()
    {
        _logger.LogWarning("Warning");
        _logger.LogVerbose("Verbose");
        _logger.LogDebug("Debug")
        _logger.LogError("Error");
        return View();
    }
}

My log window shows:

2016-04-13 12:41:24 [Warning] Warning
2016-04-13 12:41:24 [Debug] Verbose
2016-04-13 12:41:24 [Error] Error

There are other debug messages that relate to build in ASP.Net functions.

Can anyone please advise what I'm doing wrong? Thanks.

like image 371
David Hawkins Avatar asked Feb 07 '26 03:02

David Hawkins


1 Answers

I believe you also need to set MinimumLevel on the loggerFactory:

loggerFactory.MinimumLevel = LogLevel.Debug;

(ASP.NET's and Serilogs debug/verbose levels are switched in RC1, this is being rectified by RC2.)

like image 193
Nicholas Blumhardt Avatar answered Feb 09 '26 17:02

Nicholas Blumhardt



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!