0

There is Serilog in my app. It writes some information to text file, when the app is running. There is an Email form in the app, too. I want to attach last log-files to the message, but I can't because those files are being used by the process.

I've tried to set SHARED flag to true, but that didn't help.

Also, I've had an idea to pause logging by the CloseAndFlush() method, while attaching. But I don't know how to restart it.

    private static LoggerConfiguration Logger = new LoggerConfiguration()
                                                   .MinimumLevel.Information()
                                                   .WriteTo.File(Path.Combine(MailHelper.SerilogPath, $"{Program.CurrentUser.Login}_actions_log_.txt"),
                                                                 rollingInterval: RollingInterval.Hour, shared: true,
                                                                 retainedFileCountLimit: 10);

    public static void CreateLogger()
    {
        Log.Logger = Logger.CreateLogger();           
    }


    public static void PauseLogging()
    {
        Log.CloseAndFlush();
    }

The main idea is to easily attach the log-file to the message. Logging must work before and after it.

But know it's blocked by a process.

0 Answers0