Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added LogScope to all MSFT.EXT.Logger output #475

Draft
wants to merge 8 commits into
base: dev
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions RELEASE_NOTES.md
Original file line number Diff line number Diff line change
@@ -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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@ namespace Akka.Hosting.TestKit.Internals
public class XUnitLogger : Microsoft.Extensions.Logging.ILogger
{
public XUnitLogger(string category, Xunit.Abstractions.ITestOutputHelper helper, Microsoft.Extensions.Logging.LogLevel logLevel) { }
public System.IDisposable BeginScope<TState>(TState state)
where TState : notnull { }
public System.IDisposable BeginScope<TState>(TState state) { }
public bool IsEnabled(Microsoft.Extensions.Logging.LogLevel logLevel) { }
public void Log<TState>(Microsoft.Extensions.Logging.LogLevel logLevel, Microsoft.Extensions.Logging.EventId eventId, TState state, System.Exception? exception, System.Func<TState, System.Exception?, string> formatter) { }
}
Expand Down
19 changes: 17 additions & 2 deletions src/Akka.Hosting.TestKit/Internals/XUnitLogger.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
{
}

/// <inheritdoc />
public void Dispose()
{
}
}


private readonly string _category;
private readonly ITestOutputHelper _helper;
Expand Down Expand Up @@ -58,9 +73,9 @@ public bool IsEnabled(LogLevel logLevel)
};
}

public IDisposable BeginScope<TState>(TState state) where TState : notnull
public IDisposable BeginScope<TState>(TState state)
{
throw new NotImplementedException();
return NullScope.Instance;
}

private static bool TryFormatMessage<TState>(
Expand Down
6 changes: 6 additions & 0 deletions src/Akka.Hosting.Tests/Akka.Hosting.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,10 @@
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
</ItemGroup>

<ItemGroup>
<Reference Include="Akka.Hosting.TestKit">
<HintPath>bin\Debug\net6.0\Akka.Hosting.TestKit.dll</HintPath>
</Reference>
</ItemGroup>
</Project>
3 changes: 1 addition & 2 deletions src/Akka.Hosting.Tests/ExtensionsSpecs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
1 change: 1 addition & 0 deletions src/Akka.Hosting.Tests/Logging/LogMessageFormatterSpec.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
84 changes: 0 additions & 84 deletions src/Akka.Hosting.Tests/XUnitLogger.cs

This file was deleted.

26 changes: 0 additions & 26 deletions src/Akka.Hosting.Tests/XUnitLoggerProvider.cs

This file was deleted.

6 changes: 5 additions & 1 deletion src/Akka.Hosting/Logging/LoggerFactoryLogger.cs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,11 @@ protected override bool Receive(object message)

protected virtual void Log(LogEvent log, ActorPath path)
{
_akkaLogger.Log<LogEvent>(GetLogLevel(log.LogLevel()), new EventId(), log, log.Cause, (@event, exception) => @event.ToString());
using (_akkaLogger.BeginScope("{AkkaLogSource} {AkkaLogClass}", log.LogSource, log.LogClass))
{
_akkaLogger.Log(GetLogLevel(log.LogLevel()), new EventId(), log, log.Cause, (@event, exception) => @event.ToString());
}

}

private static LogLevel GetLogLevel(Event.LogLevel level)
Expand Down
5 changes: 3 additions & 2 deletions src/Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@
<PropertyGroup>
<Copyright>Copyright © 2013-2023 Akka.NET Team</Copyright>
<Authors>Akka.NET Team</Authors>
<VersionPrefix>1.5.19</VersionPrefix>
<PackageReleaseNotes>• [Update Akka.NET to 1.5.19](https://github.com/akkadotnet/akka.net/releases/tag/1.5.19)</PackageReleaseNotes>
<VersionPrefix>1.5.26</VersionPrefix>
<PackageReleaseNotes>• [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.</PackageReleaseNotes>
<PackageIcon>akkalogo.png</PackageIcon>
<PackageProjectUrl>
https://github.com/akkadotnet/Akka.Hosting
Expand Down
Loading