datalust / serilog-sinks-seq

A Serilog sink that writes events to the Seq structured log server
https://datalust.co/seq
Apache License 2.0
225 stars 50 forks source link

Buffered events upload on logger dispose fails if there is no logs yet #198

Open MaceWindu opened 1 year ago

MaceWindu commented 1 year ago
using Serilog;
using Serilog.Debugging;

internal class Program
{
    static void Main()
    {
        using var logger = new LoggerConfiguration()
            .WriteTo.Seq("http://localhost:5341", bufferBaseFilename: @"<PATH_TO_NOT_YET_CREATED_FOLDER>\logfile")
            .CreateLogger();

        // buffer folder will be created on first log write
        //logger.Information("Create bookmarks folder");

        SelfLog.Enable(msg => logger.Error($"Logger failure: {msg}"));

        // on logger dispose we try to upload buffered data and fail with
        // DirectoryNotFoundException: Could not find a part of the path 'PATH_TO_NOT_YET_CREATED_FOLDER\\logfile.bookmark'
    }
}
Exception while emitting periodic batch from Serilog.Sinks.Seq.Durable.HttpLogShipper: System.IO.DirectoryNotFoundException: Could not find a part of the path '<PATH_TO_NOT_YET_CREATED_FOLDER>\\logfile.bookmark'.
   at Microsoft.Win32.SafeHandles.SafeFileHandle.CreateFile(String fullPath, FileMode mode, FileAccess access, FileShare share, FileOptions options)
   at Microsoft.Win32.SafeHandles.SafeFileHandle.Open(String fullPath, FileMode mode, FileAccess access, FileShare share, FileOptions options, Int64 preallocationSize, Nullable`1 unixCreateMode)
   at System.IO.Strategies.OSFileStreamStrategy..ctor(String path, FileMode mode, FileAccess access, FileShare share, FileOptions options, Int64 preallocationSize, Nullable`1 unixCreateMode)
   at System.IO.Strategies.FileStreamHelpers.ChooseStrategyCore(String path, FileMode mode, FileAccess access, FileShare share, FileOptions options, Int64 preallocationSize, Nullable`1 unixCreateMode)
   at System.IO.File.Open(String path, FileMode mode, FileAccess access, FileShare share)
   at Serilog.Sinks.Seq.Durable.BookmarkFile..ctor(String bookmarkFilename)
   at Serilog.Sinks.Seq.Durable.FileSet.OpenBookmarkFile()
   at Serilog.Sinks.Seq.Durable.HttpLogShipper.OnTick()
todthomson commented 1 year ago

Looks like a bug @MaceWindu. Thanks for the bug report. We'll take a look asap and report back.