1

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..

7
  • Did you enable SelfLog to check for exceptions? github.com/serilog/serilog/wiki/Debugging-and-Diagnostics Commented May 8, 2020 at 18:44
  • yes, but I didn't get any output Commented May 8, 2020 at 19:38
  • also, if I'm adding .writeTo.Console() to the same configuration it works, only writing to file does not work. Commented May 8, 2020 at 19:51
  • Are you sure you're looking at the right place for the output of SelfLog? Commented May 8, 2020 at 19:54
  • I have added :Serilog.Debugging.SelfLog.Enable(msg => Debug.WriteLine(msg)); Serilog.Debugging.SelfLog.Enable(Console.Error); so I should see the error in console/output window? Commented May 8, 2020 at 19:57

2 Answers 2

1
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

Sign up to request clarification or add additional context in comments.

Comments

0

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.