I'm working on an ASP.NET Core 8 Web API project using Serilog to log to both the console and a file.
Everything works perfectly in development (when running locally via Visual Studio), but when I publish to IIS, no log file is created in the specified path.
My Serilog config in appsettings.json:
"Serilog": {
"Using": [ "Serilog.Sinks.Console", "Serilog.Sinks.File" ],
"MinimumLevel": {
"Default": "Information",
"Override": {
"Microsoft": "Warning",
"System": "Warning"
}
},
"WriteTo": [
{ "Name": "Console" },
{ "Name": "File",
"Args": {
"path": "C:\\NotificationSystemLogs\\log-.txt",
"rollingInterval": "Day",
"outputTemplate": "[{Timestamp:HH:mm:ss} {Level:u3}] {Message:lj}{NewLine}{Exception}"
}
}
],
"Enrich": [ "FromLogContext" ],
"Properties": {
"Application": "NotificationSystem"
}
}
In Program.cs, I have:
Log.Logger = new LoggerConfiguration()
.WriteTo.Console()
.CreateBootstrapLogger();
Log.Information("Starting up...");
builder.Host.UseSerilog((ctx, services, configuration) =>
new LoggerConfiguration()
.ReadFrom.Configuration(ctx.Configuration)
.ReadFrom.Services(services)
.Enrich.FromLogContext()
.CreateLogger()
);
What I tried so far:
- Manually created
C:\NotificationSystemLogsand gave "Everyone" full access - Also gave IIS
APPPOOL\NotificationSystemmodify permissions to the folder - Set correct path in
appsettings.json(used double backslashes) - Tried writing logs from background service and middleware — no output
- Used
SelfLog.Enable(...)for debugging Serilog itself — no errors are captured
Still no file is created in production (IIS).
The app runs fine and I can access it, but Serilog just silently doesn't write to file.
Environment:
- ASP.NET Core 8 Web API
- Hosted on IIS (Windows Server)
- AppPool Identity:
ApplicationPoolIdentity - Log folder path:
C:\NotificationSystemLogs
Question
What could be causing Serilog to not write logs to file in IIS, even though:
- The folder exists
- Permissions are correct
- No exception is thrown
- Works locally
Any ideas?