Updated
This commit is contained in:
@@ -13,8 +13,8 @@
|
||||
<Copyright>EonaCat (Jeroen Saey)</Copyright>
|
||||
<PackageTags>EonaCat;Logger;EonaCatLogger;Log;Writer;Jeroen;Saey</PackageTags>
|
||||
<PackageIconUrl />
|
||||
<Version>1.7.7</Version>
|
||||
<FileVersion>1.7.7</FileVersion>
|
||||
<Version>1.7.8</Version>
|
||||
<FileVersion>1.7.8</FileVersion>
|
||||
<PackageReadmeFile>README.md</PackageReadmeFile>
|
||||
<GenerateDocumentationFile>True</GenerateDocumentationFile>
|
||||
<PackageLicenseFile>LICENSE</PackageLicenseFile>
|
||||
|
||||
@@ -361,6 +361,17 @@ public sealed class FileLoggerProvider : BatchingLoggerProvider, IDisposable
|
||||
{
|
||||
try
|
||||
{
|
||||
if (_stream == null || !File.Exists(_filePath))
|
||||
{
|
||||
RecreateStream();
|
||||
}
|
||||
|
||||
_stream.Write(data, 0, length);
|
||||
}
|
||||
catch (IOException ioEx) when (!File.Exists(_filePath))
|
||||
{
|
||||
// File was removed while writing, recreate and retry once
|
||||
RecreateStream();
|
||||
_stream.Write(data, 0, length);
|
||||
}
|
||||
catch (Exception ex)
|
||||
@@ -378,15 +389,31 @@ public sealed class FileLoggerProvider : BatchingLoggerProvider, IDisposable
|
||||
}
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
private void FlushIfNeeded()
|
||||
private void RecreateStream()
|
||||
{
|
||||
if (_position >= FlushThreshold)
|
||||
try
|
||||
{
|
||||
FlushInternal();
|
||||
Directory.CreateDirectory(Path.GetDirectoryName(_filePath)!);
|
||||
|
||||
_stream?.Dispose();
|
||||
_stream = new FileStream(
|
||||
_filePath,
|
||||
FileMode.Append,
|
||||
FileAccess.Write,
|
||||
FileShare.ReadWrite | FileShare.Delete,
|
||||
4096,
|
||||
FileOptions.WriteThrough | FileOptions.SequentialScan);
|
||||
|
||||
_size = _stream.Length;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
RaiseError(ex);
|
||||
_running = false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private void FlushInternal()
|
||||
{
|
||||
if (_position == 0)
|
||||
@@ -396,6 +423,16 @@ public sealed class FileLoggerProvider : BatchingLoggerProvider, IDisposable
|
||||
|
||||
try
|
||||
{
|
||||
if (_stream == null || !File.Exists(_filePath))
|
||||
{
|
||||
RecreateStream();
|
||||
}
|
||||
|
||||
_stream.Write(_buffer, 0, _position);
|
||||
}
|
||||
catch (IOException ioEx) when (!File.Exists(_filePath))
|
||||
{
|
||||
RecreateStream();
|
||||
_stream.Write(_buffer, 0, _position);
|
||||
}
|
||||
catch (Exception ex)
|
||||
|
||||
Reference in New Issue
Block a user