diff --git a/EonaCat.LogStack.LogClient/EonaCat.LogStack.LogClient.csproj b/EonaCat.LogStack.LogClient/EonaCat.LogStack.LogClient.csproj index 7a40f61..bdd2cb0 100644 --- a/EonaCat.LogStack.LogClient/EonaCat.LogStack.LogClient.csproj +++ b/EonaCat.LogStack.LogClient/EonaCat.LogStack.LogClient.csproj @@ -25,7 +25,7 @@ - + diff --git a/EonaCat.LogStack.OpenTelemetryFlow/EonaCat.LogStack.OpenTelemetryFlow.csproj b/EonaCat.LogStack.OpenTelemetryFlow/EonaCat.LogStack.OpenTelemetryFlow.csproj index 5a2fcd7..aacc84a 100644 --- a/EonaCat.LogStack.OpenTelemetryFlow/EonaCat.LogStack.OpenTelemetryFlow.csproj +++ b/EonaCat.LogStack.OpenTelemetryFlow/EonaCat.LogStack.OpenTelemetryFlow.csproj @@ -32,10 +32,10 @@ - - - - + + + + diff --git a/EonaCat.LogStack.SerilogTest/EonaCat.LogStack.SerilogTest.csproj b/EonaCat.LogStack.SerilogTest/EonaCat.LogStack.SerilogTest.csproj index af014cb..7f9b542 100644 --- a/EonaCat.LogStack.SerilogTest/EonaCat.LogStack.SerilogTest.csproj +++ b/EonaCat.LogStack.SerilogTest/EonaCat.LogStack.SerilogTest.csproj @@ -12,7 +12,7 @@ - + diff --git a/EonaCat.LogStack.Status/EonaCat.LogStack.Status.csproj b/EonaCat.LogStack.Status/EonaCat.LogStack.Status.csproj index fc3d121..a3f7fc9 100644 --- a/EonaCat.LogStack.Status/EonaCat.LogStack.Status.csproj +++ b/EonaCat.LogStack.Status/EonaCat.LogStack.Status.csproj @@ -9,6 +9,6 @@ - + diff --git a/EonaCat.LogStack.WindowsEventLogFlow/EonaCat.LogStack.Flows.WindowsEventLog.csproj b/EonaCat.LogStack.WindowsEventLogFlow/EonaCat.LogStack.Flows.WindowsEventLog.csproj index 9c46043..834016f 100644 --- a/EonaCat.LogStack.WindowsEventLogFlow/EonaCat.LogStack.Flows.WindowsEventLog.csproj +++ b/EonaCat.LogStack.WindowsEventLogFlow/EonaCat.LogStack.Flows.WindowsEventLog.csproj @@ -35,8 +35,8 @@ - - + + diff --git a/EonaCat.LogStack/EonaCat.LogStack.csproj b/EonaCat.LogStack/EonaCat.LogStack.csproj index 7699868..f63570b 100644 --- a/EonaCat.LogStack/EonaCat.LogStack.csproj +++ b/EonaCat.LogStack/EonaCat.LogStack.csproj @@ -14,7 +14,7 @@ It features a rich fluent API for routing log events to dozens of destinations f EonaCat (Jeroen Saey) EonaCat;Logger;EonaCatLogStack;Log;Writer;Flows;LogStack;Memory;Speed;Jeroen;Saey - 0.0.7 + 0.0.8 README.md True LICENSE @@ -25,7 +25,7 @@ It features a rich fluent API for routing log events to dozens of destinations f - 0.0.7+{chash:10}.{c:ymd} + 0.0.8+{chash:10}.{c:ymd} true true v[0-9]* @@ -36,10 +36,11 @@ It features a rich fluent API for routing log events to dozens of destinations f - 0.0.7 + 0.0.8 EonaCat.LogStack EonaCat.LogStack https://git.saey.me/EonaCat/EonaCat.LogStack + 09d73ec1-ee68-42bb-b2bd-b0e31b635098 @@ -73,11 +74,12 @@ It features a rich fluent API for routing log events to dozens of destinations f - - - + + + + - + diff --git a/EonaCat.LogStack/EonaCatLoggerCore/EonaCatLoggerProvider.cs b/EonaCat.LogStack/EonaCatLoggerCore/EonaCatLoggerProvider.cs new file mode 100644 index 0000000..9e2238e --- /dev/null +++ b/EonaCat.LogStack/EonaCatLoggerCore/EonaCatLoggerProvider.cs @@ -0,0 +1,23 @@ +using Microsoft.Extensions.Logging; +using System; + +namespace EonaCat.LogStack.Logging; + +public sealed class EonaCatLoggerProvider : ILoggerProvider +{ + private readonly EonaCatLogStack _logStack; + public EonaCatLoggerProvider(EonaCatLogStack logStack)=>_logStack=logStack; + public Microsoft.Extensions.Logging.ILogger CreateLogger(string categoryName) => new CategoryLogger(categoryName,_logStack); + public void Dispose(){} +} + +internal sealed class CategoryLogger : Microsoft.Extensions.Logging.ILogger +{ + private readonly string _category; + private readonly EonaCatLogStack _stack; + public CategoryLogger(string category,EonaCatLogStack stack){_category=category;_stack=stack;} + public IDisposable BeginScope(TState state) where TState:notnull => NullScope.Instance; + public bool IsEnabled(LogLevel logLevel)=>true; + public void Log(LogLevel logLevel, EventId eventId, TState state, Exception? exception, Func formatter){var msg=$"[{_category}] {formatter(state,exception)}"; _stack.Log(msg);} +} +internal sealed class NullScope:IDisposable { public static readonly NullScope Instance= new(); public void Dispose(){} } diff --git a/EonaCat.LogStack/Extensions/HostApplicationBuilderExtensions.cs b/EonaCat.LogStack/Extensions/HostApplicationBuilderExtensions.cs new file mode 100644 index 0000000..6efbb9a --- /dev/null +++ b/EonaCat.LogStack/Extensions/HostApplicationBuilderExtensions.cs @@ -0,0 +1,14 @@ +using EonaCat.LogStack.Core; +using Microsoft.Extensions.Hosting; +using System; + +namespace EonaCat.LogStack.Extensions; + +public static class HostApplicationBuilderExtensions +{ + public static IHostApplicationBuilder AddEonaCatLogging(this IHostApplicationBuilder builder, Action? configure=null) + { + builder.Services.AddEonaCatLogging(configure ?? (_=>{})); + return builder; + } +} diff --git a/EonaCat.LogStack/Extensions/LoggingBuilderExtensions.cs b/EonaCat.LogStack/Extensions/LoggingBuilderExtensions.cs new file mode 100644 index 0000000..d935f66 --- /dev/null +++ b/EonaCat.LogStack/Extensions/LoggingBuilderExtensions.cs @@ -0,0 +1,18 @@ +using EonaCat.LogStack.Logging; +using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Logging; +using System; + +namespace EonaCat.LogStack.Extensions; + +public static class LoggingBuilderExtensions +{ + public static ILoggingBuilder AddEonaCatLogging(this ILoggingBuilder builder, Action? configure=null) + { + var logStack = new EonaCatLogStack(); + configure?.Invoke(logStack); + builder.Services.AddSingleton(logStack); + builder.Services.AddSingleton(); + return builder; + } +}