'Serilog not writing to file on Ubuntu
I have deployed a website to a ubuntu machine but unable to get serilog to write to file
Here is what I have:
In Program.cs (omitted unnecessary parts):
public static void Main(string[] args)
{
var environment = Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT");
var configuration = new ConfigurationBuilder()
.AddJsonFile("appsettings.json", optional: false, reloadOnChange: true)
.AddJsonFile($"appsettings.{environment}.json", optional: true)
.AddEnvironmentVariables()
.Build();
Log.Logger = new LoggerConfiguration()
.ReadFrom.Configuration(configuration)
.CreateLogger();
Also:
return Host.CreateDefaultBuilder(args)
.ConfigureWebHostDefaults(webBuilder =>
{
webBuilder
.UseUrls($"http://localhost:{port}")
.UseStartup<Startup>();
})
.UseSerilog();
in my appsetting.PreProduction.json:
"Serilog": {
"MinimumLevel": "Information",
"WriteTo": [
{
"Name": "File",
"Args": {
"path": "/var/log/myapp/",
"rollingInterval": "Day"
}
}
]
},
This works on my local machine Windows
{
"Name": "File",
"Args": {
"path": "c:\\myapp\\log.txt",
"rollingInterval": "Day"
}
},
Do I need to do anything extra permission wise?
Solution 1:[1]
I had to restart the service:
sudo systemctl restart myapp.service
also had to set permissions:
mkdir /var/log/myapp/
chown apiuser:apiuser /var/log/myapp/
chmod 740 /var/log/myapp
I kept restarting nginx but didn't know I had to restart the service too
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 |