Moved messagePrefix to DllInfo

This commit is contained in:
2025-02-17 19:12:08 +01:00
parent c5cb238f42
commit 9bc225ee36
12 changed files with 31 additions and 37 deletions

View File

@@ -20,7 +20,7 @@ public static class DllInfo
internal static string VersionName { get; }
public static string ApplicationName { get; internal set; } = "EonaCatLogger";
public static string ApplicationName { get; set; } = "EonaCatLogger";
public static string EonaCatVersion => VersionHelper.GetEonaCatVersion(Assembly.GetExecutingAssembly());
}

View File

@@ -3,7 +3,7 @@
<TargetFrameworks>.netstandard2.1; net6.0; net7.0; net8.0; net4.8;</TargetFrameworks>
<ApplicationIcon>icon.ico</ApplicationIcon>
<LangVersion>latest</LangVersion>
<FileVersion>1.4.0</FileVersion>
<FileVersion>1.4.1</FileVersion>
<Authors>EonaCat (Jeroen Saey)</Authors>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<Company>EonaCat (Jeroen Saey)</Company>
@@ -24,7 +24,7 @@
</PropertyGroup>
<PropertyGroup>
<EVRevisionFormat>1.4.0+{chash:10}.{c:ymd}</EVRevisionFormat>
<EVRevisionFormat>1.4.1+{chash:10}.{c:ymd}</EVRevisionFormat>
<EVDefault>true</EVDefault>
<EVInfo>true</EVInfo>
<EVTagMatch>v[0-9]*</EVTagMatch>

View File

@@ -3,7 +3,6 @@ using System.Collections.Concurrent;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Threading;
using System.Threading.Tasks;
using EonaCat.Logger.EonaCatCoreLogger.Internal;

View File

@@ -31,6 +31,8 @@ public class BatchingLoggerOptions
/// </summary>
public int BatchSize { get; set; } = 0;
/// <summary>
/// Gets or sets value indicating if logger accepts and queues writes.
/// </summary>

View File

@@ -1,6 +1,7 @@
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Diagnostics.SymbolStore;
using System.Threading;
using System.Threading.Tasks;
using EonaCat.Logger.Managers;

View File

@@ -28,7 +28,7 @@ public static class ExceptionExtensions
var sb = new StringBuilder();
sb.AppendLine();
sb.AppendLine("--- Exception details provided by EonaCatLogger ---");
sb.AppendLine($"--- Exception details provided by {DllInfo.ApplicationName} ---");
if (!string.IsNullOrEmpty(module))
{
sb.AppendLine(" Module : " + module);

View File

@@ -45,7 +45,13 @@ internal static class LogHelper
int severity = (int)logType;
int pri = (facility * 8) + severity;
string timestamp = dateTime.ToString("yyyy-MM-ddTHH:mm:ss.fffZ");
string syslogMessage = $"<{pri}>1 {timestamp} {hostname} {settings?.Id ?? "EonaCatLogger"} - - {formattedMessage}";
var syslogMessage = $"<{pri}>1 {timestamp} {hostname} - - {formattedMessage}";
if (settings?.Id != null)
{
syslogMessage = $"<{pri}>1 {timestamp} {hostname} {settings?.Id} - - {formattedMessage}";
}
syslogMessage = $"<{pri}>1 {timestamp} {hostname} - - {formattedMessage}";
return syslogMessage;
}
@@ -63,7 +69,7 @@ internal static class LogHelper
int severity = (int)logType;
int pri = (facility * 8) + severity;
string timestamp = dateTime.ToString("MMM dd HH:mm:ss");
string syslogMessage = $"<{pri}>{timestamp} {hostname} {settings?.Id ?? "EonaCatLogger"}: {formattedMessage}";
string syslogMessage = $"<{pri}>{timestamp} {hostname} {settings?.Id ?? DllInfo.ApplicationName}: {formattedMessage}";
return syslogMessage;
}
@@ -77,7 +83,7 @@ internal static class LogHelper
}
category ??= "General";
var sb = new StringBuilder(settings?.HeaderFormat ?? "[EonaCatLogger]");
var sb = new StringBuilder(settings?.HeaderFormat);
var timestamp = dateTime.ToString(settings?.TimestampFormat ?? "yyyy-MM-dd HH:mm:ss");
var timeLabel = settings?.UseLocalTime ?? false ? "[LOCAL]" : "[UTC]";
@@ -87,11 +93,6 @@ internal static class LogHelper
.Replace("{thread}", $"[ThreadId:{Environment.CurrentManagedThreadId}]")
.Replace("{sev}", $"[{logType}]");
if (!(settings?.RemoveMessagePrefix ?? false) && !currentMessage.Contains("[EonaCatLogger]"))
{
sb.Insert(0, "[EonaCatLogger] ");
}
if (sb.Length > 0)
{
sb.Append(" ");

View File

@@ -121,7 +121,7 @@ namespace EonaCat.Logger.Managers
{
var settings = new LoggerSettings
{
Id = "EonaCatLogger",
Id = DllInfo.ApplicationName,
};
return settings;
}
@@ -291,15 +291,9 @@ namespace EonaCat.Logger.Managers
private void SetupLogManager()
{
AppDomain.CurrentDomain.ProcessExit += ProcessExit;
_logDate = CurrentDateTime;
}
private void ProcessExit(object sender, EventArgs e)
{
Dispose();
}
private Task StopLoggingAsync()
{
WriteStopMessage();

View File

@@ -30,13 +30,7 @@ public class LoggerSettings
/// </summary>
public bool UseLocalTime { get; set; }
public string Id { get; set; } = "EonaCatLogger";
/// <summary>
/// Determines if we need to remove the prefix [EonaCatLogger] from each message (default: false)
/// </summary>
public bool RemoveMessagePrefix { get; set; }
public string Id { get; set; } = DllInfo.ApplicationName;
/// <summary>
/// Header format. Provide a string that specifies how the preamble of each message should be structured. You can use

View File

@@ -93,7 +93,7 @@ namespace EonaCat.Logger.Advanced
static Logger()
{
// Create and configure a LogManager for logging.
_logManager = new LogManager(new LoggerSettings { RemoveMessagePrefix = true });
_logManager = new LogManager(new LoggerSettings());
_logManager.OnException += _logManager_OnException;
_logManager.OnLogLevelDisabled += _logManager_OnLogLevelDisabled;
_logManager.Settings.FileLoggerOptions.FileNamePrefix = "advanced";

View File

@@ -114,7 +114,7 @@ public class Logger
if (fS.Length > limit)
{
await stream.WriteAsync("\r\n####__EONACATLOGGER_TRUNCATED___####"u8.ToArray()).ConfigureAwait(false);
await stream.WriteAsync("\r\n####___TRUNCATED___####"u8.ToArray()).ConfigureAwait(false);
}
}
}

View File

@@ -18,13 +18,14 @@ var defaultColor = Console.ForegroundColor;
// Add services to the container.
Logger logger = new Logger();
logger.UseLocalTime = true;
logger.TypesToLog.Add(ELogType.INFO);
logger.TypesToLog.Add(ELogType.WARNING);
logger.TypesToLog.Add(ELogType.ERROR);
logger.TypesToLog.Add(ELogType.CRITICAL);
logger.TypesToLog.Add(ELogType.DEBUG);
logger.TypesToLog.Add(ELogType.TRACE);
logger.TypesToLog.Add(ELogType.TRAFFIC);
logger.LoggerSettings.Id = "TEST";
logger.LoggerSettings.LogInfo();
logger.LoggerSettings.LogWarning();
logger.LoggerSettings.LogError();
logger.LoggerSettings.LogCritical();
logger.LoggerSettings.LogDebug();
logger.LoggerSettings.LogTrace();
logger.LoggerSettings.LogTraffic();
logger.LoggerSettings.OnLog += LoggerSettings_OnLog;
logger.LoggerSettings.UseMask = true;
@@ -42,7 +43,7 @@ var options = new FileLoggerOptions();
options.MaxRolloverFiles = 5;
//options.FileSizeLimit = 1 * 1024 * 1024 / 4;
options.UseLocalTime = true;
options.UseMask = true;
options.UseMask = true;
builder.Logging.AddEonaCatFileLogger(fileLoggerOptions: options, filenamePrefix: "web");
builder.Services.AddRazorPages();
@@ -125,6 +126,7 @@ void RunLoggingExceptionTests()
var loggerSettings = new LoggerSettings();
loggerSettings.FileLoggerOptions.UseLocalTime = true;
loggerSettings.UseLocalTime = true;
loggerSettings.Id = "TEST";
loggerSettings.TypesToLog.Add(ELogType.INFO);
var logger = new LogManager(loggerSettings);
@@ -219,6 +221,7 @@ async void RunMaskTest()
async Task RunLoggingTestsAsync()
{
var loggerSettings = new LoggerSettings();
loggerSettings.Id = "TEST";
loggerSettings.UseLocalTime = true;
loggerSettings.FileLoggerOptions.UseLocalTime = true;
loggerSettings.TypesToLog.Add(ELogType.INFO);