Adding support for .NET 8.0 LTS, renaming private fields to start with underscore
This commit is contained in:
@@ -24,13 +24,13 @@ namespace AMWD.Common.Logging
|
||||
{
|
||||
#region Fields
|
||||
|
||||
private bool isDisposed = false;
|
||||
private readonly CancellationTokenSource cancellationTokenSource = new();
|
||||
private bool _isDisposed = false;
|
||||
private readonly CancellationTokenSource _cancellationTokenSource = new();
|
||||
|
||||
private readonly StreamWriter fileWriter;
|
||||
private readonly Task writeTask;
|
||||
private readonly StreamWriter _fileWriter;
|
||||
private readonly Task _writeTask;
|
||||
|
||||
private readonly AsyncQueue<QueueItem> queue = new();
|
||||
private readonly AsyncQueue<QueueItem> _queue = new();
|
||||
|
||||
#endregion Fields
|
||||
|
||||
@@ -45,8 +45,8 @@ namespace AMWD.Common.Logging
|
||||
public FileLogger(string file, bool append = false, Encoding encoding = null)
|
||||
{
|
||||
FileName = file;
|
||||
fileWriter = new StreamWriter(FileName, append, encoding ?? Encoding.UTF8);
|
||||
writeTask = Task.Run(() => WriteFileAsync(cancellationTokenSource.Token));
|
||||
_fileWriter = new StreamWriter(FileName, append, encoding ?? Encoding.UTF8);
|
||||
_writeTask = Task.Run(() => WriteFileAsync(_cancellationTokenSource.Token));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -148,7 +148,7 @@ namespace AMWD.Common.Logging
|
||||
/// <inheritdoc cref="ILogger.BeginScope{TState}(TState)" />
|
||||
public IDisposable BeginScope<TState>(TState state)
|
||||
{
|
||||
if (isDisposed)
|
||||
if (_isDisposed)
|
||||
throw new ObjectDisposedException(GetType().FullName);
|
||||
|
||||
return ScopeProvider?.Push(state) ?? NullScope.Instance;
|
||||
@@ -157,7 +157,7 @@ namespace AMWD.Common.Logging
|
||||
/// <inheritdoc cref="ILogger.IsEnabled(LogLevel)" />
|
||||
public bool IsEnabled(LogLevel logLevel)
|
||||
{
|
||||
if (isDisposed)
|
||||
if (_isDisposed)
|
||||
throw new ObjectDisposedException(GetType().FullName);
|
||||
|
||||
return logLevel >= MinLevel;
|
||||
@@ -166,7 +166,7 @@ namespace AMWD.Common.Logging
|
||||
/// <inheritdoc cref="ILogger.Log{TState}(LogLevel, EventId, TState, Exception, Func{TState, Exception, string})" />
|
||||
public void Log<TState>(LogLevel logLevel, EventId eventId, TState state, Exception exception, Func<TState, Exception, string> formatter)
|
||||
{
|
||||
if (isDisposed)
|
||||
if (_isDisposed)
|
||||
throw new ObjectDisposedException(GetType().FullName);
|
||||
|
||||
if (!IsEnabled(logLevel))
|
||||
@@ -197,13 +197,13 @@ namespace AMWD.Common.Logging
|
||||
/// <inheritdoc cref="IDisposable.Dispose" />
|
||||
public void Dispose()
|
||||
{
|
||||
if (!isDisposed)
|
||||
if (!_isDisposed)
|
||||
{
|
||||
isDisposed = true;
|
||||
_isDisposed = true;
|
||||
|
||||
cancellationTokenSource.Cancel();
|
||||
writeTask.GetAwaiter().GetResult();
|
||||
fileWriter.Dispose();
|
||||
_cancellationTokenSource.Cancel();
|
||||
_writeTask.GetAwaiter().GetResult();
|
||||
_fileWriter.Dispose();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -213,7 +213,7 @@ namespace AMWD.Common.Logging
|
||||
|
||||
private void WriteMessage(string name, LogLevel logLevel, int eventId, string message, Exception exception)
|
||||
{
|
||||
queue.Enqueue(new QueueItem
|
||||
_queue.Enqueue(new QueueItem
|
||||
{
|
||||
Timestamp = UseUtcTimestamp ? DateTime.UtcNow : DateTime.Now,
|
||||
Name = name,
|
||||
@@ -236,7 +236,7 @@ namespace AMWD.Common.Logging
|
||||
QueueItem[] items;
|
||||
try
|
||||
{
|
||||
items = await queue.DequeueAvailableAsync(cancellationToken: token).ConfigureAwait(false);
|
||||
items = await _queue.DequeueAvailableAsync(cancellationToken: token).ConfigureAwait(false);
|
||||
}
|
||||
catch (OperationCanceledException)
|
||||
{
|
||||
@@ -302,10 +302,10 @@ namespace AMWD.Common.Logging
|
||||
|
||||
sb.Append(message.Replace("\n", "\n" + timestampPadding + logLevelPadding));
|
||||
|
||||
await fileWriter.WriteLineAsync(sb.ToString()).ConfigureAwait(false);
|
||||
await _fileWriter.WriteLineAsync(sb.ToString()).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
await fileWriter.FlushAsync().ConfigureAwait(false);
|
||||
await _fileWriter.FlushAsync().ConfigureAwait(false);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user