Hi,
I was trying to setup my project ASP.NET MVC with .Net Framework 4.7.2 to use NLog and Autofac.
It just strange that , when writing a log to a file it was working as expected, but when trying to log in database it doesn't log anything.
Im trying to instantiate it like this inside the controller:
public class TestController {
private readonly ILogger _logger;
public TestController(ILogger logger){
_logger = logger;
}
}
or like this:
public class TestController {
private readonly ILogger<TestController> _logger;
public TestController(ILogger<TestController> logger){
_logger = logger;
}
}
But still doesn't log anything, Can anyone please guide me?
PS:
This code was able to insert log in database, but not the above setup
// get a Logger object and log exception here using NLog.
// this will use the "databaseLogger" logger from our NLog.config file
NLog.Logger logger = NLog.LogManager.GetLogger("databaseLogger");
// add custom message and pass in the exception
logger.Error(ex, "Whoops!");
Hi, I was trying to setup my project ASP.NET MVC with .Net Framework 4.7.2 to use NLog and Autofac. It just strange that , when writing a log to a file it was working as expected, but when trying to log in database it doesn't log anything.
Here is my config in DI:
NLog.config:
Im trying to instantiate it like this inside the controller:
or like this:
But still doesn't log anything, Can anyone please guide me?
PS:
This code was able to insert log in database, but not the above setup
Thanks, Jonathan