Skip to content

Commit 3038518

Browse files
Merge pull request akkadotnet#56 from akkadotnet/dev
Akka.Logger.Serilog v1.3.9 Release
2 parents 697c12c + a3f9f3c commit 3038518

File tree

9 files changed

+171
-24
lines changed

9 files changed

+171
-24
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
This is the Serilog integration plugin for Akka.NET. Please check out our [documentation](http://getakka.net/articles/utilities/serilog.html) on how to get the most out of this plugin.
44

5-
Targets Serilog 2.6.0.
5+
Targets Serilog 2.7.1.
66

77
### Semantic Logging Syntax
88
If you intend on using any of the Serilog semantic logging formats in your logging strings, __you need to use the SerilogLoggingAdapter__ inside your instrumented code or there could be elsewhere inside parts of your `ActorSystem`:

RELEASE_NOTES.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
#### 1.3.9 August 23 2018 ####
2+
* [Fixed: Regression: ForContext API doesn't apply changes](https://github.com/akkadotnet/Akka.Logger.Serilog/issues/51)
3+
* Upgraded to Akka.NET v1.3.9.
4+
* Upgraded to Serilog v2.7.1.
5+
16
#### 1.3.6 April 28 2018 ####
27
* Restored `SerilogLogMessageFormatter` in order to fix [Bug: `LogEvent.ToString()` blows up when using Serilog semantic formatting](https://github.com/akkadotnet/Akka.Logger.Serilog/issues/43).
38
* Upgraded to [Akka.NET v1.3.6](https://github.com/akkadotnet/akka.net/releases/tag/v1.3.6).

src/Akka.Logger.Serilog.Tests/Akka.Logger.Serilog.Tests.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
</PropertyGroup>
77

88
<ItemGroup>
9-
<PackageReference Include="Akka.TestKit.Xunit2" Version="1.3.6" />
9+
<PackageReference Include="Akka.TestKit.Xunit2" Version="1.3.9" />
1010
<PackageReference Include="FluentAssertions" Version="5.3.0" />
1111
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="$(TestSdkVersion)" />
1212
<PackageReference Include="Serilog.Sinks.ColoredConsole" Version="3.0.1" />
Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
using System.Threading.Tasks;
6+
using Akka.Actor;
7+
using Akka.Configuration;
8+
using Akka.Event;
9+
using FluentAssertions;
10+
using Serilog;
11+
using Serilog.Events;
12+
using Xunit;
13+
using Xunit.Abstractions;
14+
using LogEvent = Akka.Event.LogEvent;
15+
16+
namespace Akka.Logger.Serilog.Tests
17+
{
18+
public class ForContextSpecs : TestKit.Xunit2.TestKit
19+
{
20+
public static readonly Config Config = @"akka.loglevel = DEBUG
21+
akka.loggers=[""Akka.Logger.Serilog.SerilogLogger, Akka.Logger.Serilog""]";
22+
private ILoggingAdapter _loggingAdapter;
23+
private readonly TestSink _sink = new TestSink();
24+
25+
public ForContextSpecs(ITestOutputHelper helper) : base(Config, output: helper)
26+
{
27+
global::Serilog.Log.Logger = new LoggerConfiguration()
28+
.WriteTo.Sink(_sink)
29+
.MinimumLevel.Information()
30+
.CreateLogger();
31+
32+
var logSource = Sys.Name;
33+
var logClass = typeof(ActorSystem);
34+
35+
_loggingAdapter = new SerilogLoggingAdapter(Sys.EventStream, logSource, logClass);
36+
}
37+
38+
[Fact]
39+
public void ShouldPassAlongAdditionalContext()
40+
{
41+
var traceId = Guid.NewGuid();
42+
var spanId = Guid.NewGuid();
43+
var context1 = _loggingAdapter.ForContext("traceId", traceId);
44+
var context2 = context1.ForContext("spanId", spanId);
45+
46+
_sink.Clear();
47+
AwaitCondition(() => _sink.Writes.Count == 0);
48+
49+
context1.Info("hi");
50+
AwaitCondition(() => _sink.Writes.Count == 1);
51+
52+
_sink.Writes.TryDequeue(out var logEvent).Should().BeTrue();
53+
logEvent.Level.Should().Be(LogEventLevel.Information);
54+
logEvent.Properties.ContainsKey("traceId").Should().BeTrue();
55+
logEvent.Properties["traceId"].ToString().Should().BeEquivalentTo(traceId.ToString());
56+
57+
_sink.Clear();
58+
AwaitCondition(() => _sink.Writes.Count == 0);
59+
60+
context2.Info("bye");
61+
62+
AwaitCondition(() => _sink.Writes.Count == 1);
63+
64+
_sink.Writes.TryDequeue(out var logEvent2).Should().BeTrue();
65+
66+
logEvent2.Level.Should().Be(LogEventLevel.Information);
67+
68+
// needs to still have the context from context1
69+
logEvent2.Properties.ContainsKey("traceId").Should().BeTrue();
70+
logEvent2.Properties["traceId"].ToString().Should().BeEquivalentTo(traceId.ToString());
71+
72+
// and its own context from context2
73+
logEvent2.Properties.ContainsKey("spanId").Should().BeTrue();
74+
logEvent2.Properties["spanId"].ToString().Should().BeEquivalentTo(spanId.ToString());
75+
}
76+
77+
[Fact]
78+
public void ShouldPassAlongAdditionalContextWorkaround()
79+
{
80+
var traceId = Guid.NewGuid();
81+
var spanId = Guid.NewGuid();
82+
var context1 = (SerilogLoggingAdapter)_loggingAdapter.ForContext("traceId", traceId);
83+
var context2 = (SerilogLoggingAdapter)context1.ForContext("spanId", spanId);
84+
85+
_sink.Clear();
86+
AwaitCondition(() => _sink.Writes.Count == 0);
87+
88+
context1.Info("hi");
89+
AwaitCondition(() => _sink.Writes.Count == 1);
90+
91+
_sink.Writes.TryDequeue(out var logEvent).Should().BeTrue();
92+
logEvent.Level.Should().Be(LogEventLevel.Information);
93+
logEvent.Properties.ContainsKey("traceId").Should().BeTrue();
94+
logEvent.Properties["traceId"].ToString().Should().BeEquivalentTo(traceId.ToString());
95+
96+
_sink.Clear();
97+
AwaitCondition(() => _sink.Writes.Count == 0);
98+
99+
context2.Info("bye");
100+
101+
AwaitCondition(() => _sink.Writes.Count == 1);
102+
103+
_sink.Writes.TryDequeue(out var logEvent2).Should().BeTrue();
104+
105+
logEvent2.Level.Should().Be(LogEventLevel.Information);
106+
107+
// needs to still have the context from context1
108+
logEvent2.Properties.ContainsKey("traceId").Should().BeTrue();
109+
logEvent2.Properties["traceId"].ToString().Should().BeEquivalentTo(traceId.ToString());
110+
111+
// and its own context from context2
112+
logEvent2.Properties.ContainsKey("spanId").Should().BeTrue();
113+
logEvent2.Properties["spanId"].ToString().Should().BeEquivalentTo(spanId.ToString());
114+
115+
}
116+
}
117+
}
118+
119+
120+
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
using System.Collections.Concurrent;
2+
using Serilog.Core;
3+
using Serilog.Events;
4+
5+
namespace Akka.Logger.Serilog.Tests
6+
{
7+
/// <inheritdoc />
8+
/// <summary>
9+
/// Basic concurrent sink implementation for testing the final output from Serilog
10+
/// </summary>
11+
public sealed class TestSink : ILogEventSink
12+
{
13+
public ConcurrentQueue<global::Serilog.Events.LogEvent> Writes { get; private set; } = new ConcurrentQueue<global::Serilog.Events.LogEvent>();
14+
15+
/// <summary>
16+
/// Resets the contents of the queue
17+
/// </summary>
18+
public void Clear()
19+
{
20+
Writes = new ConcurrentQueue<LogEvent>();
21+
}
22+
23+
public void Emit(global::Serilog.Events.LogEvent logEvent)
24+
{
25+
Writes.Enqueue(logEvent);
26+
}
27+
}
28+
}

src/Akka.Logger.Serilog/Akka.Logger.Serilog.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@
1010
</PropertyGroup>
1111

1212
<ItemGroup>
13-
<PackageReference Include="Akka" Version="1.3.6" />
14-
<PackageReference Include="Serilog" Version="2.6.0" />
13+
<PackageReference Include="Serilog" Version="2.7.1" />
14+
<PackageReference Include="Akka" Version="1.3.9" />
1515
</ItemGroup>
1616

1717
<PropertyGroup Condition=" '$(Configuration)' == 'Release' ">

src/Akka.Logger.Serilog/SerilogLoggingAdapter.cs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ private SerilogLoggingAdapter(LoggingBus bus, string logSource, Type logClass, C
4242
/// </summary>
4343
/// <param name="format">The message that is being logged.</param>
4444
/// <param name="args">An optional list of items used to format the message.</param>
45-
public new void Debug(string format, params object[] args)
45+
public override void Debug(string format, params object[] args)
4646
{
4747
base.Debug(format, BuildArgs(args));
4848
}
@@ -52,17 +52,17 @@ private SerilogLoggingAdapter(LoggingBus bus, string logSource, Type logClass, C
5252
/// </summary>
5353
/// <param name="format">The message that is being logged.</param>
5454
/// <param name="args">An optional list of items used to format the message.</param>
55-
public new void Info(string format, params object[] args)
55+
public override void Info(string format, params object[] args)
5656
{
5757
base.Info(format, BuildArgs(args));
5858
}
5959

6060
/// <summary>
6161
/// Obsolete. Use <see cref="M:Akka.Event.ILoggingAdapter.Warning(System.String,System.Object[])" /> instead!
6262
/// </summary>
63-
/// <param name="format">N/A</param>
64-
/// <param name="args">N/A</param>
65-
public new void Warn(string format, params object[] args)
63+
/// <param name="format">The message that is being logged.</param>
64+
/// <param name="args">An optional list of items used to format the message.</param>
65+
public override void Warn(string format, params object[] args)
6666
{
6767
base.Warning(format, BuildArgs(args));
6868
}
@@ -72,7 +72,7 @@ private SerilogLoggingAdapter(LoggingBus bus, string logSource, Type logClass, C
7272
/// </summary>
7373
/// <param name="format">The message that is being logged.</param>
7474
/// <param name="args">An optional list of items used to format the message.</param>
75-
public new void Warning(string format, params object[] args)
75+
public override void Warning(string format, params object[] args)
7676
{
7777
base.Warning(format, BuildArgs(args));
7878
}
@@ -82,7 +82,7 @@ private SerilogLoggingAdapter(LoggingBus bus, string logSource, Type logClass, C
8282
/// </summary>
8383
/// <param name="format">The message that is being logged.</param>
8484
/// <param name="args">An optional list of items used to format the message.</param>
85-
public new void Error(string format, params object[] args)
85+
public override void Error(string format, params object[] args)
8686
{
8787
base.Error(format, BuildArgs(args));
8888
}
@@ -93,7 +93,7 @@ private SerilogLoggingAdapter(LoggingBus bus, string logSource, Type logClass, C
9393
/// <param name="cause">The exception associated with this message.</param>
9494
/// <param name="format">The message that is being logged.</param>
9595
/// <param name="args">An optional list of items used to format the message.</param>
96-
public new void Error(Exception cause, string format, params object[] args)
96+
public override void Error(Exception cause, string format, params object[] args)
9797
{
9898
base.Error(cause, format, BuildArgs(args));
9999
}
@@ -102,7 +102,7 @@ private SerilogLoggingAdapter(LoggingBus bus, string logSource, Type logClass, C
102102
/// <param name="logLevel">The level used to log the message.</param>
103103
/// <param name="format">The message that is being logged.</param>
104104
/// <param name="args">An optional list of items used to format the message.</param>
105-
public new void Log(LogLevel logLevel, string format, params object[] args)
105+
public override void Log(LogLevel logLevel, string format, params object[] args)
106106
{
107107
base.Log(logLevel, format, BuildArgs(args));
108108
}

src/Akka.Logger.Serilog/SerilogLoggingAdapterExtensions.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,7 @@ public static class SerilogLoggingAdapterExtensions
1515
/// <param name="destructureObjects">If true, the value will be serialized as a structured object if possible; if false, the object will be recorded as a scalar or simple array.</param>
1616
public static ILoggingAdapter ForContext(this ILoggingAdapter adapter, string propertyName, object value, bool destructureObjects = false)
1717
{
18-
var customAdapter = adapter as SerilogLoggingAdapter;
19-
return customAdapter == null ? adapter : customAdapter.SetContextProperty(propertyName, value, destructureObjects);
18+
return !(adapter is SerilogLoggingAdapter customAdapter) ? adapter : customAdapter.SetContextProperty(propertyName, value, destructureObjects);
2019
}
2120

2221
/// <summary>

src/common.props

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,10 @@
33
<PackageTags>akka;actors;actor model;Akka;concurrency;serilog</PackageTags>
44
<Copyright>Copyright © 2013-2018 Akka.NET Team</Copyright>
55
<Authors>Akka.NET Team</Authors>
6-
<PackageReleaseNotes>Restored `SerilogLogMessageFormatter` in order to fix [Bug: `LogEvent.ToString()` blows up when using Serilog semantic formatting](https://github.com/akkadotnet/Akka.Logger.Serilog/issues/43).
7-
Upgraded to [Akka.NET v1.3.6](https://github.com/akkadotnet/akka.net/releases/tag/v1.3.6).
8-
If you intend on using any of the Serilog semantic logging formats in your logging strings, __you need to use the SerilogLoggingAdapter__ inside your instrumented code or there could be elsewhere inside parts of your `ActorSystem`:
9-
```csharp
10-
var log = Context.GetLogger&lt;SerilogLoggingAdapter&gt;(); // correct
11-
log.Info("My boss makes me use {semantic} logging", "semantic"); // serilog semantic logging format
12-
```
13-
This will allow all logging events to be consumed anywhere inside the `ActorSystem`, including places like the Akka.NET TestKit, without throwing `FormatException`s when they encounter semantic logging syntax outside of the `SerilogLogger`.</PackageReleaseNotes>
14-
<VersionPrefix>1.3.6</VersionPrefix>
6+
<PackageReleaseNotes>[Fixed: Regression: ForContext API doesn't apply changes](https://github.com/akkadotnet/Akka.Logger.Serilog/issues/51)
7+
Upgraded to Akka.NET v1.3.9.
8+
Upgraded to Serilog v2.7.1.</PackageReleaseNotes>
9+
<VersionPrefix>1.3.9</VersionPrefix>
1510
<PackageIconUrl>http://getakka.net/images/akkalogo.png</PackageIconUrl>
1611
<PackageProjectUrl>https://github.com/akkadotnet/Akka.Logger.Serilog</PackageProjectUrl>
1712
<PackageLicenseUrl>https://github.com/akkadotnet/Akka.Logger.Serilog/blob/master/LICENSE</PackageLicenseUrl>

0 commit comments

Comments
 (0)