I am testing some basic file logging with Asp.Net Core and I using Serilog as it's quick to setup.
The issue I having is when I log a message from the HomeController using the built in ILogger there is no mention of the controller in the file output. For example.. the logger is in the controller is like this and being injected the usual way in the constructor..
private readonly ILogger<HomeController> _logger;
I am am logging something as a test like this
_logger.LogError("Test error log");
This appears in the file like this.. with no mention of HomeController.
2019-11-28T11:36:52.7735997+00:00 8000000c-0003-fe00-b63f-84710c7967bb [INF] test info log (72772865)
Also where/how do I format this date so it isn't so long? Its not clear from the docs if its done in the json, or startup.cs. And I dont need the 8000000a-0003-fe00-b63f-84710c7967bb request id.
In startup.cs this is set up as follows
public void Configure(IApplicationBuilder app, IWebHostEnvironment env, ILoggerFactory loggerFactory)
{
loggerFactory.AddFile("Logs/HPPartnerPortal-{Date}.txt");
My config.json specifies the default of
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft": "Warning"
}
I notice you can add File logging using the configure method in your startup.cs as I did above.. or you can add it in program.cs as specified in the
like this
Host.CreateDefaultBuilder(args)
//we are setting up logging in Startup.cs so this is not needed ? !
.ConfigureLogging(logging =>
{
logging.ClearProviders();
logging.AddConsole();
logging.AddDebug();
//logging.AddFile("Logs/myapp-{Date}.txt"); -- AddFile not recognised?!
})
The problem here is it doesnt recognise AddFile even though I have added Serilog.Extensions.Logging.File This is 1.1.0 which is the latest version in nuget.