'serilog not logging with ubuntu ASP.NET Core
I'm using ubuntu 19.10 with .net core 3.1. This is my first time using Serilog, with the following configuration:
<TargetFramework>netcoreapp3.1</TargetFramework>
<PackageReference Include="Serilog.AspNetCore" Version="3.2.0" />
<PackageReference Include="Serilog.sinks.file" Version="4.1.0" />
public class Program
{
public static void Main(string[] args)
{
Log.Logger = new LoggerConfiguration()
.MinimumLevel.Debug()
.MinimumLevel.Override("Microsoft", LogEventLevel.Warning)
.Enrich.FromLogContext().WriteTo.File("/tmp/log/LogFile.txt")
.CreateLogger();
Log.Information("Starting up the service");
try{
CreateHostBuilder(args).Build().Run();
}catch(Exception e)
{
Log.Fatal(e, "There was a problem starting the service");
return ;
}
finally
{
Log.CloseAndFlush();
}
}
public static IHostBuilder CreateHostBuilder(string[] args) =>
Host.CreateDefaultBuilder(args)
.ConfigureServices((hostContext, services) =>
{
services.AddHostedService<Worker>();
}).UseSerilog();
}}
I don't get any exception and the log file stays empty. What am I missing ?
Thanks for your help..
Solution 1:[1]
It's probably a file privilege issue , if I run "sudo dotnet run" then it works.I dont know why I didn't get any exception from Serilog that indicates that this is the issue.
Solution 2:[2]
sudo chown www-data:www-data folder-that-is-the-app
sudo chown -R www-data folder-that-is-the-app
did the trick for me
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | shirli |
| Solution 2 | Edi |
