I have a simple web API using asp.net 5. I've added a Trace Listener so that the ILogger outputs to a file when I add Debug. This works fine in testing (within VS2019) in both debug and release mode. But when I deploy it to IIS it outputs nothing. It does manage to create the logfile but never puts anything in it.
my appsettings.json is the same in dev as in Prod ... is there another file I need?
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft": "Warning",
"Microsoft.Hosting.Lifetime": "Information"
}
}
}
here is my abSoundAPI.runtimeconfig.json as well
{
"runtimeOptions": {
"tfm": "net5.0",
"framework": {
"name": "Microsoft.AspNetCore.App",
"version": "5.0.0"
},
"configProperties": {
"System.GC.Server": true,
"System.Runtime.Serialization.EnableUnsafeBinaryFormatterSerialization": false
}
},
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft": "Information",
"Microsoft.Hosting.Lifetime": "Information"
}
}
}
Here is my Program class:
public static void Main(string[] args)
{
TextWriterTraceListener fileOutListener = new("abSoundAPI.log", "fileOutListnener");
Trace.Listeners.Add(fileOutListener);
Trace.AutoFlush = true;
try
{
CreateHostBuilder(args).Build().Run();
}
catch (Exception e)
{
Trace.WriteLine($"Fatal Exception {e.Message}");
throw new Exception("Failed to start!");
}
finally
{
//Trace.Flush();
}
}
public static IHostBuilder CreateHostBuilder(string[] args) =>
Host.CreateDefaultBuilder(args)
.ConfigureLogging((context, logging) =>
{
logging.ClearProviders(); // see comments in code F12 on the CreateHostBuilder above
logging.AddConfiguration(context.Configuration.GetSection("Logging"));
logging.AddDebug();
logging.AddConsole();
})
.ConfigureWebHostDefaults(webBuilder =>
{
webBuilder.UseStartup<Startup>();
});