As the title says, why my Logger not showing in the console when I run the application with dotnet run
I'm using the Logger in class other than Controller though.
Here's the code:
public class TestController : Controller
{
private readonly ITestService service;
public TestController(ITestService service)
{
this.service = service;
}
}
public class TestService : ITestService
{
private readonly ILogger logger;
public TestService(ILogger<TestService> logger)
{
this.logger = logger;
}
public Task SomeFunction()
{
logger.Information("Do some function");
return Task.CompleteTask;
}
}
I'm using Microsoft.Extensions.Logging for the ILogger
Here's how I register my service in Startup.cs:
services.Scan(scan => scan
.FromAssemblyOf<ITestService>()
.AddClasses(classes => classes
.Where(t => t.Name.EndsWith("Service")))
.AsImplementedInterfaces()
.WithTransientLifetime());
I'm using Scrutor for the Scan
And here's my configuration for my Program.cs:
WebHost.CreateDefaultBuilder(args)
.ConfigureServices(services => services.AddAutofac())
.ConfigureAppConfiguration((context, builder) =>
{
builder.SetBasePath(Directory.GetCurrentDirectory())
.AddJsonFile("appsettings.json", optional: false, reloadOnChange: true)
.AddJsonFile($"appsettings.{Environment.MachineName}.json", optional: true, reloadOnChange: true);
})
.ConfigureLogging((hostingContext, logging) =>
{
logging.AddConfiguration(hostingContext.Configuration.GetSection("Logging"));
logging.AddConsole();
logging.AddDebug();
})
.UseStartup<Startup>();
As the code, I tried to call logger with logger.Information(""); and the logger didn't show in my console.
What's wrong with my code?
Sorry for my English. Thanks in advance
Edit:
Almost forget, here's my appsettings.json :
{
"Logging": {
"LogLevel": {
"Default": "Debug",
"System": "Information",
"Microsoft": "Information"
},
"Console": {
"IncludeScopes": "true"
}
},
"AllowedHosts": "*"
}