diff --git a/RELEASE_NOTES.md b/RELEASE_NOTES.md index bb61c33d..f876d958 100644 --- a/RELEASE_NOTES.md +++ b/RELEASE_NOTES.md @@ -1,6 +1,7 @@ -## [1.5.25] / 17 June 2024 +## [1.5.26] / 17 July 2024 -* [Update Akka.NET to 1.5.25](https://github.com/akkadotnet/akka.net/releases/tag/1.5.25), which resolves a critical bug: [Akka.Logging: v1.5.21 appears to have truncated log source, timestamps, etc from all log messages ](https://github.com/akkadotnet/akka.net/issues/7255) +* [Update Akka.NET to 1.5.26](https://github.com/akkadotnet/akka.net/releases/tag/1.5.26) +* Added scopes to all Microsoft.Extensions.Logging output, for better semantic logging support. ## [1.5.24] / 10 June 2024 diff --git a/src/Akka.Hosting.TestKit/Internals/XUnitLogger.cs b/src/Akka.Hosting.TestKit/Internals/XUnitLogger.cs index 3d47f4e6..476511e5 100644 --- a/src/Akka.Hosting.TestKit/Internals/XUnitLogger.cs +++ b/src/Akka.Hosting.TestKit/Internals/XUnitLogger.cs @@ -7,6 +7,21 @@ namespace Akka.Hosting.TestKit.Internals public class XUnitLogger: ILogger { private const string NullFormatted = "[null]"; + + internal sealed class NullScope : IDisposable + { + public static NullScope Instance { get; } = new NullScope(); + + private NullScope() + { + } + + /// + public void Dispose() + { + } + } + private readonly string _category; private readonly ITestOutputHelper _helper; @@ -60,7 +75,7 @@ public bool IsEnabled(LogLevel logLevel) public IDisposable BeginScope(TState state) where TState : notnull { - throw new NotImplementedException(); + return NullScope.Instance; } private static bool TryFormatMessage( diff --git a/src/Akka.Hosting.Tests/Akka.Hosting.Tests.csproj b/src/Akka.Hosting.Tests/Akka.Hosting.Tests.csproj index 4651277f..353d3976 100644 --- a/src/Akka.Hosting.Tests/Akka.Hosting.Tests.csproj +++ b/src/Akka.Hosting.Tests/Akka.Hosting.Tests.csproj @@ -31,4 +31,10 @@ Always + + + + bin\Debug\net6.0\Akka.Hosting.TestKit.dll + + diff --git a/src/Akka.Hosting.Tests/ExtensionsSpecs.cs b/src/Akka.Hosting.Tests/ExtensionsSpecs.cs index 9005f701..0c4050e4 100644 --- a/src/Akka.Hosting.Tests/ExtensionsSpecs.cs +++ b/src/Akka.Hosting.Tests/ExtensionsSpecs.cs @@ -8,8 +8,7 @@ using System.Threading.Tasks; using Akka.Actor; using Akka.Configuration; -using Akka.Event; -using Akka.TestKit.Xunit2.Internals; +using Akka.Hosting.TestKit.Internals; using FluentAssertions; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Hosting; diff --git a/src/Akka.Hosting.Tests/Logging/LogMessageFormatterSpec.cs b/src/Akka.Hosting.Tests/Logging/LogMessageFormatterSpec.cs index dfd2adb7..94fe72f9 100644 --- a/src/Akka.Hosting.Tests/Logging/LogMessageFormatterSpec.cs +++ b/src/Akka.Hosting.Tests/Logging/LogMessageFormatterSpec.cs @@ -12,6 +12,7 @@ using Akka.Actor; using Akka.Configuration; using Akka.Event; +using Akka.Hosting.TestKit.Internals; using FluentAssertions; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Hosting; diff --git a/src/Akka.Hosting.Tests/XUnitLogger.cs b/src/Akka.Hosting.Tests/XUnitLogger.cs deleted file mode 100644 index 2dbfb036..00000000 --- a/src/Akka.Hosting.Tests/XUnitLogger.cs +++ /dev/null @@ -1,98 +0,0 @@ -using System; -using Microsoft.Extensions.Logging; -using Xunit.Abstractions; - -namespace Akka.Hosting.Tests; - -public class XUnitLogger: ILogger -{ - internal sealed class NullScope : IDisposable - { - public static NullScope Instance { get; } = new NullScope(); - - private NullScope() - { - } - - /// - public void Dispose() - { - } - } - - private const string NullFormatted = "[null]"; - - private readonly string _category; - private readonly ITestOutputHelper _helper; - private readonly LogLevel _logLevel; - - public XUnitLogger(string category, ITestOutputHelper helper, LogLevel logLevel) - { - _category = category; - _helper = helper; - _logLevel = logLevel; - } - - public void Log(LogLevel logLevel, EventId eventId, TState state, Exception? exception, Func formatter) - { - if (!IsEnabled(logLevel)) - return; - - if (!TryFormatMessage(state, exception, formatter, out var formattedMessage)) - return; - - WriteLogEntry(logLevel, eventId, formattedMessage, exception); - } - - private void WriteLogEntry(LogLevel logLevel, EventId eventId, string? message, Exception? exception) - { - var level = logLevel switch - { - LogLevel.Critical => "CRT", - LogLevel.Debug => "DBG", - LogLevel.Error => "ERR", - LogLevel.Information => "INF", - LogLevel.Warning => "WRN", - LogLevel.Trace => "DBG", - _ => "???" - }; - - var msg = $"{DateTime.Now}:{level}:{_category}:{eventId} {message}"; - if (exception != null) - msg += $"\n{exception.GetType()} {exception.Message}\n{exception.StackTrace}"; - _helper.WriteLine(msg); - } - - public bool IsEnabled(LogLevel logLevel) - { - return logLevel switch - { - LogLevel.None => false, - _ => logLevel >= _logLevel - }; - } - - public IDisposable BeginScope(TState state) - { - return NullScope.Instance; - } - - private static bool TryFormatMessage( - TState state, - Exception? exception, - Func formatter, - out string? result) - { - formatter = formatter ?? throw new ArgumentNullException(nameof(formatter)); - - var formattedMessage = formatter(state, exception); - if (formattedMessage == NullFormatted) - { - result = null; - return false; - } - - result = formattedMessage; - return true; - } -} \ No newline at end of file diff --git a/src/Akka.Hosting.Tests/XUnitLoggerProvider.cs b/src/Akka.Hosting.Tests/XUnitLoggerProvider.cs deleted file mode 100644 index c5f8d18c..00000000 --- a/src/Akka.Hosting.Tests/XUnitLoggerProvider.cs +++ /dev/null @@ -1,26 +0,0 @@ -using Microsoft.Extensions.Logging; -using Xunit.Abstractions; - -namespace Akka.Hosting.Tests; - -public class XUnitLoggerProvider : ILoggerProvider -{ - private readonly ITestOutputHelper _helper; - private readonly LogLevel _logLevel; - - public XUnitLoggerProvider(ITestOutputHelper helper, LogLevel logLevel) - { - _helper = helper; - _logLevel = logLevel; - } - - public void Dispose() - { - // no-op - } - - public ILogger CreateLogger(string categoryName) - { - return new XUnitLogger(categoryName, _helper, _logLevel); - } -} \ No newline at end of file diff --git a/src/Directory.Build.props b/src/Directory.Build.props index 1b450d8c..1fbc792c 100644 --- a/src/Directory.Build.props +++ b/src/Directory.Build.props @@ -2,8 +2,9 @@ Copyright © 2013-2023 Akka.NET Team Akka.NET Team - 1.5.19 - • [Update Akka.NET to 1.5.19](https://github.com/akkadotnet/akka.net/releases/tag/1.5.19) + 1.5.26 + • [Update Akka.NET to 1.5.26](https://github.com/akkadotnet/akka.net/releases/tag/1.5.26) +• Added scopes to all Microsoft.Extensions.Logging output%2C for better semantic logging support. akkalogo.png https://github.com/akkadotnet/Akka.Hosting