Как установить путь Serilog в appsettings.Production. json в Убунто - PullRequest
0 голосов
/ 21 марта 2020

У меня есть этот раздел appsetting для serilog в моем asp. net core 2

 "Serilog": {
    "FilePath": "/var/log/MyApp/log.txt",
    "Template": "{Timestamp:yyyy-MM-dd HH:mm:ss.fff zzz} [{Level:u3}] {Message:lj}{NewLine}{Exception}",
    "RollingInterval": "Day"
  },

Когда я опубликую sh мое приложение в Ubunto 16.5, я не получу никакого журнала в путь, определенный выше.

Я пробовал эти пути, но ни один из них не создает журнал:

"FilePath": "/log.txt"
"FilePath": "log.txt"

Я запускаю свое ядро ​​asp. net с пользователем, у которого есть все разрешения

Любое предложение приветствуется.

вот где я добавляю Serilog:

private void ConfigureLogger(IServiceCollection serviceCollection)
{
    var filePath = Configuration.GetSection("Serilog:FilePath").Value;
    var rollingInterval = (RollingInterval)Enum.Parse(typeof(RollingInterval), Configuration.GetSection("Serilog:RollingInterval").Value); 

    Serilog.Core.Logger logger = new LoggerConfiguration()
        .WriteTo.Async(a => a.File(path: filePath, 
            rollingInterval: rollingInterval,
            outputTemplate: Configuration.GetSection("Serilog:Template").Value))
        .MinimumLevel.Verbose()
        .CreateLogger();

    serviceCollection.AddLogging(item => item.AddSerilog(logger));
}
...