不要在appsettings.json的Serilog區段改path了,那個沒用,
直接在Program.cs裡改才有用啦
===============
string exePath = AppDomain.CurrentDomain.BaseDirectory;
string logFolderPath = Path.Combine(exePath, "logs");
string logFilePath = Path.Combine(logFolderPath, "log-.txt");
// Ensure the logs folder exists
if (!Directory.Exists(logFolderPath))
{
Directory.CreateDirectory(logFolderPath);
}
// Configure Serilog
Log.Logger = new LoggerConfiguration()
.WriteTo.Console()
.WriteTo.File(
path: logFilePath,
rollingInterval: RollingInterval.Day,
outputTemplate: "[{Timestamp:yyyy-MM-dd HH:mm:ss} {Level:u3}] {Message:lj}{NewLine}{Exception}"
)
.CreateLogger();
================
試了很久才試出來.....不知道之後的版本有沒有改掉這個bug