Updated
This commit is contained in:
@@ -8,7 +8,7 @@
|
||||
net6.0;
|
||||
</TargetFrameworks>
|
||||
<ApplicationIcon>icon.ico</ApplicationIcon>
|
||||
<Version>1.0.2</Version>
|
||||
<Version>1.0.3</Version>
|
||||
<Authors>EonaCat (Jeroen Saey)</Authors>
|
||||
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
|
||||
<Company>EonaCat (Jeroen Saey)</Company>
|
||||
@@ -17,7 +17,7 @@
|
||||
<Description>EonaCat.Logger is a logging library created for .NET Standard.</Description>
|
||||
<PackageReleaseNotes>Public release version</PackageReleaseNotes>
|
||||
<Copyright>EonaCat (Jeroen Saey)</Copyright>
|
||||
<PackageTags>EonaCat, Logger, .NET Standard, EonaCatLogger, Log, Writer Jeroen, Saey</PackageTags>
|
||||
<PackageTags>EonaCat;Logger;.NET Standard;EonaCatLogger;Log;Writer;Jeroen;Saey</PackageTags>
|
||||
<PackageIconUrl />
|
||||
<PackageReadmeFile>README.md</PackageReadmeFile>
|
||||
<GenerateDocumentationFile>True</GenerateDocumentationFile>
|
||||
@@ -27,21 +27,21 @@
|
||||
<RepositoryType>git</RepositoryType>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<None Remove="icon.png" />
|
||||
<None Include="..\LICENSE">
|
||||
<Pack>True</Pack>
|
||||
<PackagePath>\</PackagePath>
|
||||
</None>
|
||||
<None Include="..\README.md">
|
||||
<Pack>True</Pack>
|
||||
<PackagePath>\</PackagePath>
|
||||
</None>
|
||||
<None Include="icon.png">
|
||||
<Pack>True</Pack>
|
||||
<PackagePath></PackagePath>
|
||||
</None>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Remove="icon.png" />
|
||||
<None Include="..\LICENSE">
|
||||
<Pack>True</Pack>
|
||||
<PackagePath>\</PackagePath>
|
||||
</None>
|
||||
<None Include="..\README.md">
|
||||
<Pack>True</Pack>
|
||||
<PackagePath>\</PackagePath>
|
||||
</None>
|
||||
<None Include="icon.png">
|
||||
<Pack>True</Pack>
|
||||
<PackagePath></PackagePath>
|
||||
</None>
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.AspNetCore.Http.Abstractions" Version="2.2.0" />
|
||||
@@ -54,10 +54,6 @@
|
||||
<Pack>True</Pack>
|
||||
<PackagePath>\</PackagePath>
|
||||
</None>
|
||||
<None Update="LICENSE.x">
|
||||
<Pack>True</Pack>
|
||||
<PackagePath>\</PackagePath>
|
||||
</None>
|
||||
<None Update="README.md">
|
||||
<Pack>True</Pack>
|
||||
<PackagePath>\</PackagePath>
|
||||
|
||||
@@ -1,7 +1,9 @@
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using EonaCat.Logger.Helpers;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Microsoft.Extensions.Options;
|
||||
using System;
|
||||
using System.Runtime;
|
||||
|
||||
namespace EonaCat.Logger.Extensions
|
||||
{
|
||||
|
||||
@@ -126,9 +126,8 @@ namespace EonaCat.Logger
|
||||
System.IO.StreamWriter file = new System.IO.StreamWriter(LogFile, true);
|
||||
foreach (LogMessage item in group)
|
||||
{
|
||||
file.WriteAsync(item.Message);
|
||||
file.Write(item.Message);
|
||||
}
|
||||
|
||||
file.Close();
|
||||
completed = true;
|
||||
}
|
||||
|
||||
@@ -1,8 +1,9 @@
|
||||
using EonaCat.logger.Managers;
|
||||
using EonaCat.Logger.Managers;
|
||||
using EonaCatLogger.EonaCatCoreLogger.Models;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using System;
|
||||
using System.Text;
|
||||
using System.Runtime;
|
||||
|
||||
namespace EonaCat.Logger.Internal
|
||||
{
|
||||
@@ -48,6 +49,19 @@ namespace EonaCat.Logger.Internal
|
||||
}
|
||||
|
||||
_provider.AddMessage(timestamp, message);
|
||||
|
||||
var EonaCatMessage = 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);
|
||||
}
|
||||
}
|
||||
|
||||
public void Log<TState>(LogLevel logLevel, EventId eventId, TState state, Exception exception, Func<TState, Exception, string> formatter)
|
||||
|
||||
@@ -54,16 +54,21 @@ namespace EonaCat.Logger.Internal
|
||||
|
||||
if (_currentBatch.Count > 0)
|
||||
{
|
||||
bool isBatchWritten = false;
|
||||
try
|
||||
{
|
||||
await WriteMessagesAsync(_currentBatch, _cancellationTokenSource.Token);
|
||||
isBatchWritten = true;
|
||||
}
|
||||
catch
|
||||
{
|
||||
// ignored
|
||||
}
|
||||
|
||||
_currentBatch.Clear();
|
||||
if (isBatchWritten)
|
||||
{
|
||||
_currentBatch.Clear();
|
||||
}
|
||||
}
|
||||
|
||||
await IntervalAsync(_interval, _cancellationTokenSource.Token);
|
||||
|
||||
@@ -12,6 +12,7 @@ namespace EonaCatLogger.EonaCatCoreLogger.Models
|
||||
public DateTime DateTime { get; set; }
|
||||
public string Message { get; set; }
|
||||
public ELogType LogType { get; set; }
|
||||
public string Origin { get; set; }
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
|
||||
@@ -24,10 +24,6 @@ namespace EonaCat.Logger.Managers
|
||||
{
|
||||
private readonly object _batton = new object();
|
||||
private DateTime _logDate;
|
||||
public event LogDelegate OnLog;
|
||||
public delegate void LogDelegate(LogManager logger, ELogType logLevel, EonaCatLogMessage message);
|
||||
|
||||
|
||||
public ELogType LogType;
|
||||
private ILoggerProvider LoggerProvider { get; set; }
|
||||
private ILoggerFactory LoggerFactory { get; set; }
|
||||
@@ -119,7 +115,15 @@ namespace EonaCat.Logger.Managers
|
||||
IServiceCollection serviceCollection = new ServiceCollection();
|
||||
serviceCollection.AddLogging(builder => builder.AddEonaCatFileLogger(configuration =>
|
||||
{
|
||||
configuration = Settings.FileLoggerOptions;
|
||||
configuration.MaxWriteTries = Settings.FileLoggerOptions.MaxWriteTries;
|
||||
configuration.RetainedFileCountLimit = Settings.FileLoggerOptions.RetainedFileCountLimit;
|
||||
configuration.FlushPeriod = Settings.FileLoggerOptions.FlushPeriod;
|
||||
configuration.IsEnabled = Settings.FileLoggerOptions.IsEnabled;
|
||||
configuration.BatchSize = Settings.FileLoggerOptions.BatchSize;
|
||||
configuration.FileSizeLimit = Settings.FileLoggerOptions.FileSizeLimit;
|
||||
configuration.LogDirectory = Settings.FileLoggerOptions.LogDirectory;
|
||||
configuration.FileNamePrefix = Settings.FileLoggerOptions.FileNamePrefix;
|
||||
configuration.MaxRolloverFiles = Settings.FileLoggerOptions.MaxRolloverFiles;
|
||||
}));
|
||||
|
||||
var serviceProvider = serviceCollection.BuildServiceProvider();
|
||||
@@ -178,11 +182,23 @@ namespace EonaCat.Logger.Managers
|
||||
Write(dateTime, remainder, logType);
|
||||
}
|
||||
|
||||
var EonaCatMessage = new EonaCatLogMessage { DateTime = dateTime, Message = currentMessage, LogType = logType };
|
||||
OnLog?.Invoke(this, logType, EonaCatMessage);
|
||||
var EonaCatMessage = new EonaCatLogMessage
|
||||
{
|
||||
DateTime = dateTime,
|
||||
Message = currentMessage,
|
||||
LogType = logType
|
||||
};
|
||||
|
||||
if (Settings != null)
|
||||
{
|
||||
EonaCatMessage.Origin = string.IsNullOrWhiteSpace(Settings.LogOrigin) ? "LogManager" : Settings.LogOrigin;
|
||||
Settings?.OnLogEvent(EonaCatMessage);
|
||||
}
|
||||
|
||||
Settings?.OnLogEvent(EonaCatMessage);
|
||||
}
|
||||
|
||||
public void Reset() => OnLog = null;
|
||||
public void Reset() => Settings?.ResetLogEvent();
|
||||
|
||||
public LogManager(LoggerSettings settings, string serverIp, int serverPort, string id = "EonaCatLogger")
|
||||
{
|
||||
@@ -223,13 +239,16 @@ namespace EonaCat.Logger.Managers
|
||||
Settings.FileLoggerOptions.LogDirectory = logFolder;
|
||||
}
|
||||
|
||||
if (defaultPrefix)
|
||||
if (string.IsNullOrWhiteSpace(Settings.FileLoggerOptions.FileNamePrefix))
|
||||
{
|
||||
Settings.FileLoggerOptions.FileNamePrefix = "EonaCat";
|
||||
}
|
||||
else
|
||||
{
|
||||
Settings.FileLoggerOptions.FileNamePrefix = string.Empty;
|
||||
if (defaultPrefix)
|
||||
{
|
||||
Settings.FileLoggerOptions.FileNamePrefix = "EonaCat";
|
||||
}
|
||||
else
|
||||
{
|
||||
Settings.FileLoggerOptions.FileNamePrefix = string.Empty;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,8 +1,7 @@
|
||||
using System.IO;
|
||||
using System;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using EonaCat.Logger.Syslog;
|
||||
using System.Runtime;
|
||||
using EonaCatLogger.EonaCatCoreLogger.Models;
|
||||
|
||||
namespace EonaCat.Logger.Managers
|
||||
{
|
||||
@@ -11,6 +10,10 @@ namespace EonaCat.Logger.Managers
|
||||
/// </summary>
|
||||
public class LoggerSettings
|
||||
{
|
||||
public event LogDelegate OnLog;
|
||||
public delegate void LogDelegate(EonaCatLogMessage message);
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Header format. Provide a string that specifies how the preamble of each message should be structured. You can use variables including:
|
||||
/// {ts}: UTC timestamp
|
||||
@@ -67,11 +70,6 @@ namespace EonaCat.Logger.Managers
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Minimum severity required to send a message.
|
||||
/// </summary>
|
||||
public ESeverity MinimumSeverity { get; set; } = ESeverity.Debug;
|
||||
|
||||
/// <summary>
|
||||
/// Enable or disable use of color for console messages.
|
||||
/// </summary>
|
||||
@@ -148,6 +146,11 @@ namespace EonaCat.Logger.Managers
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Set the origin of where the OnLog event was inititated
|
||||
/// </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;
|
||||
@@ -169,5 +172,14 @@ namespace EonaCat.Logger.Managers
|
||||
}
|
||||
}
|
||||
|
||||
internal void OnLogEvent(EonaCatLogMessage eonaCatLogMessage)
|
||||
{
|
||||
OnLog?.Invoke(eonaCatLogMessage);
|
||||
}
|
||||
|
||||
internal void ResetLogEvent()
|
||||
{
|
||||
OnLog = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user