Updated
This commit is contained in:
@@ -13,8 +13,8 @@
|
|||||||
<Copyright>EonaCat (Jeroen Saey)</Copyright>
|
<Copyright>EonaCat (Jeroen Saey)</Copyright>
|
||||||
<PackageTags>EonaCat;Logger;EonaCatLogger;Log;Writer;Jeroen;Saey</PackageTags>
|
<PackageTags>EonaCat;Logger;EonaCatLogger;Log;Writer;Jeroen;Saey</PackageTags>
|
||||||
<PackageIconUrl />
|
<PackageIconUrl />
|
||||||
<Version>1.7.7</Version>
|
<Version>1.7.8</Version>
|
||||||
<FileVersion>1.7.7</FileVersion>
|
<FileVersion>1.7.8</FileVersion>
|
||||||
<PackageReadmeFile>README.md</PackageReadmeFile>
|
<PackageReadmeFile>README.md</PackageReadmeFile>
|
||||||
<GenerateDocumentationFile>True</GenerateDocumentationFile>
|
<GenerateDocumentationFile>True</GenerateDocumentationFile>
|
||||||
<PackageLicenseFile>LICENSE</PackageLicenseFile>
|
<PackageLicenseFile>LICENSE</PackageLicenseFile>
|
||||||
|
|||||||
@@ -361,6 +361,17 @@ public sealed class FileLoggerProvider : BatchingLoggerProvider, IDisposable
|
|||||||
{
|
{
|
||||||
try
|
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);
|
_stream.Write(data, 0, length);
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
@@ -378,15 +389,31 @@ public sealed class FileLoggerProvider : BatchingLoggerProvider, IDisposable
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
private void RecreateStream()
|
||||||
private void FlushIfNeeded()
|
|
||||||
{
|
{
|
||||||
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()
|
private void FlushInternal()
|
||||||
{
|
{
|
||||||
if (_position == 0)
|
if (_position == 0)
|
||||||
@@ -396,6 +423,16 @@ public sealed class FileLoggerProvider : BatchingLoggerProvider, IDisposable
|
|||||||
|
|
||||||
try
|
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);
|
_stream.Write(_buffer, 0, _position);
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
|
|||||||
Reference in New Issue
Block a user