Updated packages

This commit is contained in:
2023-06-26 19:07:27 +02:00
parent a592aabef1
commit 478aa15b4f
15 changed files with 92 additions and 103 deletions

View File

@@ -1,4 +1,4 @@
namespace EonaCat.Logger.Helpers
namespace EonaCat.Logger
{
// This file is part of the EonaCat project(s) which is released under the Apache License.
// See the LICENSE file or go to https://EonaCat.com/License for full license details.
@@ -6,7 +6,7 @@
public static class DllInfo
{
public const string NAME = "EonaCatLogger";
public const string VERSION = "1.0.0";
public const string VERSION = "1.1.0";
static DllInfo()
{
@@ -14,10 +14,10 @@
#if DEBUG
isDebug = true;
#endif
VERSION_NAME = isDebug ? "DEBUG" : "RELEASE";
VersionName = isDebug ? "DEBUG" : "RELEASE";
}
internal static string VERSION_NAME { get; }
internal static string VersionName { get; }
public static string ApplicationName { get; internal set; } = "EonaCatLogger";
}

View File

@@ -2,14 +2,13 @@
<PropertyGroup>
<TargetFrameworks>
netstandard2.0;
netstandard2.1;
netstandard2.1;
net5.0;
net6.0;
net7.0;
</TargetFrameworks>
<ApplicationIcon>icon.ico</ApplicationIcon>
<Version>1.0.9</Version>
<Version>1.1.0</Version>
<Authors>EonaCat (Jeroen Saey)</Authors>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<Company>EonaCat (Jeroen Saey)</Company>
@@ -45,7 +44,6 @@
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Http.Abstractions" Version="2.2.0" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="7.0.0" />
<PackageReference Include="Microsoft.Extensions.Logging" Version="7.0.0" />
</ItemGroup>

View File

@@ -1,11 +1,8 @@
using EonaCat.Logger.Helpers;
using System;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Options;
using System;
using System.Runtime;
namespace EonaCat.Logger.Extensions
namespace EonaCat.Logger.EonaCatCoreLogger.Extensions
{
// This file is part of the EonaCat project(s) which is released under the Apache License.
// See the LICENSE file or go to https://EonaCat.com/License for full license details.

View File

@@ -1,8 +1,8 @@
using EonaCat.Logger.Internal;
using System;
using System;
using System.IO;
using EonaCat.Logger.EonaCatCoreLogger.Internal;
namespace EonaCat.Logger
namespace EonaCat.Logger.EonaCatCoreLogger
{
// This file is part of the EonaCat project(s) which is released under the Apache License.
// See the LICENSE file or go to https://EonaCat.com/License for full license details.

View File

@@ -1,15 +1,14 @@
using EonaCat.Logger.Internal;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Options;
using System;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime;
using System.Threading;
using System.Threading.Tasks;
using EonaCat.Logger.EonaCatCoreLogger.Internal;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Options;
namespace EonaCat.Logger
namespace EonaCat.Logger.EonaCatCoreLogger
{
// This file is part of the EonaCat project(s) which is released under the Apache License.
// See the LICENSE file or go to https://EonaCat.com/License for full license details.
@@ -27,10 +26,10 @@ namespace EonaCat.Logger
private readonly int _maxRolloverFiles;
private readonly int _maxTries;
private int _rollOverCount = 0;
private static readonly object _writeLock = new object();
private static readonly object _rollOverLock = new object();
private static readonly object WriteLock = new object();
private static readonly object RollOverLock = new object();
private string _logFile;
private bool rollingOver;
private bool _rollingOver;
/// <summary>
/// The file to which log messages should be appended.
@@ -95,26 +94,26 @@ namespace EonaCat.Logger
File.Delete(rollOverFile);
}
fileInfo.CopyTo(rollOverFile);
File.WriteAllText(LogFile, string.Empty);
await File.WriteAllTextAsync(LogFile, string.Empty, cancellationToken).ConfigureAwait(false);
}
else
{
lock (_rollOverLock)
lock (RollOverLock)
{
rollingOver = true;
_rollingOver = true;
MoveRolloverLogFiles();
rollingOver = false;
_rollingOver = false;
}
}
}
}
while (rollingOver)
while (_rollingOver)
{
await Task.Delay(100);
await Task.Delay(100, cancellationToken).ConfigureAwait(false);
}
lock (_writeLock)
lock (WriteLock)
{
int tries = 0;
bool completed = false;

View File

@@ -1,10 +1,9 @@
using EonaCat.logger.Managers;
using System;
using EonaCat.Logger.EonaCatCoreLogger.Models;
using EonaCat.Logger.Managers;
using EonaCatLogger.EonaCatCoreLogger.Models;
using Microsoft.Extensions.Logging;
using System;
namespace EonaCat.Logger.Internal
namespace EonaCat.Logger.EonaCatCoreLogger.Internal
{
// This file is part of the EonaCat project(s) which is released under the Apache License.
// See the LICENSE file or go to https://EonaCat.com/License for full license details.
@@ -49,18 +48,16 @@ namespace EonaCat.Logger.Internal
_provider.AddMessage(timestamp, message);
var EonaCatMessage = new EonaCatLogMessage
var currentMessage = new EonaCatLogMessage
{
DateTime = timestamp.DateTime,
Message = message,
LogType = logLevel.FromLogLevel()
};
if (_loggerSettings != null)
{
EonaCatMessage.Origin = string.IsNullOrWhiteSpace(_loggerSettings.LogOrigin) ? "BatchingLogger" : _loggerSettings.LogOrigin;
_loggerSettings?.OnLogEvent(EonaCatMessage);
}
if (_loggerSettings == null) return;
currentMessage.Origin = string.IsNullOrWhiteSpace(_loggerSettings.LogOrigin) ? "BatchingLogger" : _loggerSettings.LogOrigin;
_loggerSettings?.OnLogEvent(currentMessage);
}
public void Log<TState>(LogLevel logLevel, EventId eventId, TState state, Exception exception, Func<TState, Exception, string> formatter)

View File

@@ -1,6 +1,6 @@
using System;
namespace EonaCat.Logger.Internal
namespace EonaCat.Logger.EonaCatCoreLogger.Internal
{
// This file is part of the EonaCat project(s) which is released under the Apache License.
// See the LICENSE file or go to https://EonaCat.com/License for full license details.

View File

@@ -1,13 +1,12 @@
using EonaCat.Logger.Helpers;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Options;
using System;
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Options;
namespace EonaCat.Logger.Internal
namespace EonaCat.Logger.EonaCatCoreLogger.Internal
{
// This file is part of the EonaCat project(s) which is released under the Apache License.
// See the LICENSE file or go to https://EonaCat.com/License for full license details.
@@ -39,9 +38,9 @@ namespace EonaCat.Logger.Internal
protected abstract Task WriteMessagesAsync(IEnumerable<LogMessage> messages, CancellationToken token);
private async Task ProcessLogQueue(object state)
private async Task ProcessLogQueueAsync(object state)
{
await WriteMessagesAsync(new List<LogMessage> { new LogMessage { Message = $"[{DllInfo.ApplicationName}] {DllInfo.ApplicationName} started.{Environment.NewLine}", Timestamp = DateTimeOffset.Now } }, _cancellationTokenSource.Token);
await WriteMessagesAsync(new List<LogMessage> { new LogMessage { Message = $"[{DllInfo.ApplicationName}] {DllInfo.ApplicationName} started.{Environment.NewLine}", Timestamp = DateTimeOffset.Now } }, _cancellationTokenSource.Token).ConfigureAwait(false);
while (!_cancellationTokenSource.IsCancellationRequested)
{
int limit = _batchSize <= 0 ? int.MaxValue : _batchSize;
@@ -57,7 +56,7 @@ namespace EonaCat.Logger.Internal
bool isBatchWritten = false;
try
{
await WriteMessagesAsync(_currentBatch, _cancellationTokenSource.Token);
await WriteMessagesAsync(_currentBatch, _cancellationTokenSource.Token).ConfigureAwait(false);
isBatchWritten = true;
}
catch
@@ -71,9 +70,9 @@ namespace EonaCat.Logger.Internal
}
}
await IntervalAsync(_interval, _cancellationTokenSource.Token);
await IntervalAsync(_interval, _cancellationTokenSource.Token).ConfigureAwait(false);
}
await WriteMessagesAsync(new List<LogMessage> { new LogMessage { Message = $"[{DllInfo.ApplicationName}] {DllInfo.ApplicationName} stopped.{Environment.NewLine}", Timestamp = DateTimeOffset.Now } }, _cancellationTokenSource.Token);
await WriteMessagesAsync(new List<LogMessage> { new LogMessage { Message = $"[{DllInfo.ApplicationName}] {DllInfo.ApplicationName} stopped.{Environment.NewLine}", Timestamp = DateTimeOffset.Now } }, _cancellationTokenSource.Token).ConfigureAwait(false);
}
protected virtual Task IntervalAsync(TimeSpan interval, CancellationToken cancellationToken)
@@ -92,18 +91,18 @@ namespace EonaCat.Logger.Internal
_cancellationTokenSource = new CancellationTokenSource();
_outputTask = Task.Factory.StartNew(
ProcessLogQueue,
ProcessLogQueueAsync,
null,
TaskCreationOptions.LongRunning);
}
private void Stop()
private async Task StopAsync()
{
_cancellationTokenSource.Cancel();
try
{
_outputTask.Wait(_interval);
await _outputTask.ConfigureAwait(false);
}
catch (TaskCanceledException)
{
@@ -115,7 +114,9 @@ namespace EonaCat.Logger.Internal
public void Dispose()
{
Stop();
#pragma warning disable CS4014
StopAsync();
#pragma warning restore CS4014
GC.SuppressFinalize(this);
}

View File

@@ -1,6 +1,6 @@
using System;
namespace EonaCat.Logger.Internal
namespace EonaCat.Logger.EonaCatCoreLogger.Internal
{
// This file is part of the EonaCat project(s) which is released under the Apache License.
// See the LICENSE file or go to https://EonaCat.com/License for full license details.

View File

@@ -1,8 +1,7 @@
using EonaCat.Logger;
using System;
using EonaCat.Logger.Helpers;
using System;
namespace EonaCatLogger.EonaCatCoreLogger.Models
namespace EonaCat.Logger.EonaCatCoreLogger.Models
{
// This file is part of the EonaCat project(s) which is released under the Apache License.
// See the LICENSE file or go to https://EonaCat.com/License for full license details.

View File

@@ -1,14 +1,14 @@
using System;
using System.IO;
namespace EonaCat.Extensions
namespace EonaCat.Logger.Extensions
{
// This file is part of the EonaCat project(s) which is released under the Apache License.
// See the LICENSE file or go to https://EonaCat.com/License for full license details.
public class OffsetStream : Stream
{
private const int BUFFERSIZE = 4096;
private const int BufferSize = 4096;
public OffsetStream(Stream stream, long offset = 0, long length = 0, bool readOnly = false, bool ownStream = false)
{
@@ -230,7 +230,7 @@ namespace EonaCat.Extensions
public void WriteTo(Stream stream)
{
WriteTo(stream, BUFFERSIZE);
WriteTo(stream, BufferSize);
}
public void WriteTo(Stream stream, int bufferSize)

View File

@@ -27,7 +27,7 @@ namespace EonaCat.Logger.Helpers
public static Dictionary<T, string> Names { get; }
public static Dictionary<string, T> Values { get; private set; }
public static Dictionary<string, T> Values { get; }
public static string ToString(T value)
{

View File

@@ -1,23 +1,20 @@
using EonaCat.Logger;
using EonaCat.Logger.Managers;
using EonaCat.Logger.Syslog;
using Microsoft.Extensions.Logging;
using System;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Net;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using EonaCat.Logger.Syslog;
using Microsoft.Extensions.Logging;
namespace EonaCat.logger.Managers
namespace EonaCat.Logger.Managers
{
public static class LogHelper
{
private static readonly object _fileLock = new object();
private static readonly object FileLock = new object();
/// <summary>
/// Format a message with the specified header
@@ -204,7 +201,7 @@ namespace EonaCat.logger.Managers
internal static void SendFile(ILogger logger, LoggerSettings settings, ELogType logType, string message, int maxTries = 3)
{
lock (_fileLock)
lock (FileLock)
{
if (logger == null) return;
if (settings == null) return;

View File

@@ -1,9 +1,6 @@
using EonaCat.logger.Managers;
using EonaCat.Logger.Exceptions;
using EonaCat.Logger.Extensions;
using EonaCat.Logger.Exceptions;
using EonaCat.Logger.Helpers;
using EonaCat.Logger.Syslog;
using EonaCatLogger.EonaCatCoreLogger.Models;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using System;
@@ -11,6 +8,9 @@ using System.Collections.Generic;
using System.IO;
using System.Threading;
using System.Threading.Tasks;
using EonaCat.Logger.EonaCatCoreLogger;
using EonaCat.Logger.EonaCatCoreLogger.Extensions;
using EonaCat.Logger.EonaCatCoreLogger.Models;
namespace EonaCat.Logger.Managers
{
@@ -37,8 +37,8 @@ namespace EonaCat.Logger.Managers
private bool _disposed;
private static LogManager _instance;
private LoggerSettings _settings;
private CancellationTokenSource _TokenSource = new CancellationTokenSource();
private CancellationToken _Token;
private readonly CancellationTokenSource _tokenSource = new CancellationTokenSource();
private CancellationToken _token;
/// <summary>
/// Default Logger Instance with it's default configuration
@@ -84,7 +84,7 @@ namespace EonaCat.Logger.Managers
if (disposing)
{
StopLogging();
_TokenSource.Cancel();
_tokenSource.Cancel();
}
_disposed = true;
@@ -92,7 +92,7 @@ namespace EonaCat.Logger.Managers
private void StartNewLog()
{
if (_TokenSource.IsCancellationRequested)
if (_tokenSource.IsCancellationRequested)
{
return;
}
@@ -180,7 +180,7 @@ namespace EonaCat.Logger.Managers
Write(dateTime, remainder, logType, writeToConsole);
}
var EonaCatMessage = new EonaCatLogMessage
var logMessage = new EonaCatLogMessage
{
DateTime = dateTime,
Message = currentMessage,
@@ -189,11 +189,11 @@ namespace EonaCat.Logger.Managers
if (Settings != null)
{
EonaCatMessage.Origin = string.IsNullOrWhiteSpace(Settings.LogOrigin) ? "LogManager" : Settings.LogOrigin;
Settings?.OnLogEvent(EonaCatMessage);
logMessage.Origin = string.IsNullOrWhiteSpace(Settings.LogOrigin) ? "LogManager" : Settings.LogOrigin;
Settings?.OnLogEvent(logMessage);
}
Settings?.OnLogEvent(EonaCatMessage);
Settings?.OnLogEvent(logMessage);
}
public void Reset() => Settings?.ResetLogEvent();
@@ -252,7 +252,7 @@ namespace EonaCat.Logger.Managers
private void SetupLogManager()
{
_Token = _TokenSource.Token;
_token = _tokenSource.Token;
AppDomain.CurrentDomain.ProcessExit += ProcessExit;
Console.CancelKeyPress += new ConsoleCancelEventHandler(Console_CancelKeyPress);
@@ -274,7 +274,7 @@ namespace EonaCat.Logger.Managers
{
IsRunning = false;
Write(DateTime.Now, $"{DllInfo.ApplicationName} stopped.");
Task.Delay(500);
Task.Delay(500, _token);
}
public LogManager(string logFolder = null, bool defaultPrefix = true)

View File

@@ -1,7 +1,8 @@
using System;
using System.Collections.Generic;
using EonaCat.Logger.EonaCatCoreLogger;
using EonaCat.Logger.EonaCatCoreLogger.Models;
using EonaCat.Logger.Syslog;
using EonaCatLogger.EonaCatCoreLogger.Models;
namespace EonaCat.Logger.Managers
{
@@ -27,12 +28,12 @@ namespace EonaCat.Logger.Managers
{
get
{
return _HeaderFormat;
return _headerFormat;
}
set
{
if (string.IsNullOrEmpty(value)) _HeaderFormat = "";
else _HeaderFormat = value;
if (string.IsNullOrEmpty(value)) _headerFormat = "";
else _headerFormat = value;
}
}
@@ -43,12 +44,12 @@ namespace EonaCat.Logger.Managers
{
get
{
return _TimestampFormat;
return _timestampFormat;
}
set
{
if (string.IsNullOrEmpty(value)) throw new ArgumentNullException(nameof(HeaderFormat));
_TimestampFormat = value;
_timestampFormat = value;
}
}
@@ -61,12 +62,12 @@ namespace EonaCat.Logger.Managers
{
get
{
return _EnableConsole;
return _enableConsole;
}
set
{
if (value) _EnableConsole = ConsoleExists();
else _EnableConsole = false;
if (value) _enableConsole = ConsoleExists();
else _enableConsole = false;
}
}
@@ -137,12 +138,12 @@ namespace EonaCat.Logger.Managers
{
get
{
return _MaxMessageLength;
return _maxMessageLength;
}
set
{
if (value < 32) throw new ArgumentException("Maximum message length must be at least 32.");
_MaxMessageLength = value;
_maxMessageLength = value;
}
}
@@ -151,10 +152,10 @@ namespace EonaCat.Logger.Managers
/// </summary>
public string LogOrigin { get; set; }
private string _HeaderFormat = "{ts} {host} {thread} {sev}";
private string _TimestampFormat = "yyyy-MM-dd HH:mm:ss";
private bool _EnableConsole = true;
private int _MaxMessageLength = 1024;
private string _headerFormat = "{ts} {host} {thread} {sev}";
private string _timestampFormat = "yyyy-MM-dd HH:mm:ss";
private bool _enableConsole = true;
private int _maxMessageLength = 1024;
private ColorSchema _colors = new ColorSchema();