Skip to content

Commit 5ae93b5

Browse files
Merge pull request #110 from akkadotnet/dev
1.4.8 Release
2 parents 3c37714 + 4eb8590 commit 5ae93b5

File tree

5 files changed

+307
-5
lines changed

5 files changed

+307
-5
lines changed

RELEASE_NOTES.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,7 @@
1+
#### 1.4.8 June 23 2020 ####
2+
3+
* Updated to [Akka.NET v1.4.8](https://github.com/akkadotnet/akka.net/releases/tag/1.4.8)
4+
* Support for exceptions logging in non-error log levels [#109](https://github.com/akkadotnet/Akka.Logger.Serilog/pull/109)
5+
16
#### 1.4.3 March 27 2020 ####
27
* Updated Akka.Logger.Serilog to [Akka.NET v1.4.3](https://getakka.net/community/whats-new/akkadotnet-v1.4.html)
Lines changed: 294 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,294 @@
1+
using System;
2+
using Akka.Actor;
3+
using Akka.Configuration;
4+
using Akka.Event;
5+
using FluentAssertions;
6+
using Serilog;
7+
using Serilog.Events;
8+
using Xunit;
9+
using Xunit.Abstractions;
10+
11+
namespace Akka.Logger.Serilog.Tests
12+
{
13+
public class LogMessageSpecs : TestKit.Xunit2.TestKit
14+
{
15+
public static readonly Config Config = @"akka.loglevel = DEBUG
16+
akka.loggers=[""Akka.Logger.Serilog.SerilogLogger, Akka.Logger.Serilog""]";
17+
18+
private readonly ILoggingAdapter _loggingAdapter;
19+
private readonly TestSink _sink = new TestSink();
20+
21+
public LogMessageSpecs(ITestOutputHelper helper) : base(Config, output: helper)
22+
{
23+
global::Serilog.Log.Logger = new LoggerConfiguration()
24+
.WriteTo.Sink(_sink)
25+
.MinimumLevel.Debug()
26+
.CreateLogger();
27+
_loggingAdapter = Sys.Log;
28+
}
29+
30+
[Fact]
31+
public void ShouldLogDebugLevelMessage()
32+
{
33+
var context = _loggingAdapter;
34+
35+
_sink.Clear();
36+
AwaitCondition(() => _sink.Writes.Count == 0);
37+
38+
context.Debug("hi");
39+
AwaitCondition(() => _sink.Writes.Count == 1);
40+
41+
_sink.Writes.TryDequeue(out var logEvent).Should().BeTrue();
42+
logEvent.Level.Should().Be(LogEventLevel.Debug);
43+
logEvent.RenderMessage().Should().Contain("hi");
44+
}
45+
46+
[Fact]
47+
public void ShouldLogDebugLevelMessageWithArgs()
48+
{
49+
var context = _loggingAdapter;
50+
51+
_sink.Clear();
52+
AwaitCondition(() => _sink.Writes.Count == 0);
53+
54+
context.Debug("hi {0}", "test");
55+
AwaitCondition(() => _sink.Writes.Count == 1);
56+
57+
_sink.Writes.TryDequeue(out var logEvent).Should().BeTrue();
58+
logEvent.Level.Should().Be(LogEventLevel.Debug);
59+
logEvent.RenderMessage().Should().Contain("hi \"test\"");
60+
}
61+
62+
[Fact]
63+
public void ShouldLogDebugLevelMessageWithException()
64+
{
65+
var context = _loggingAdapter;
66+
67+
_sink.Clear();
68+
AwaitCondition(() => _sink.Writes.Count == 0);
69+
70+
var exception = new Exception("BOOM!!!");
71+
context.Debug(exception, "hi");
72+
AwaitCondition(() => _sink.Writes.Count == 1);
73+
74+
_sink.Writes.TryDequeue(out var logEvent).Should().BeTrue();
75+
logEvent.Level.Should().Be(LogEventLevel.Debug);
76+
logEvent.Exception.Should().Be(exception);
77+
}
78+
79+
[Fact]
80+
public void ShouldLogDebugLevelMessageWithArgsAndException()
81+
{
82+
var context = _loggingAdapter;
83+
84+
_sink.Clear();
85+
AwaitCondition(() => _sink.Writes.Count == 0);
86+
87+
var exception = new Exception("BOOM!!!");
88+
context.Debug(exception, "hi {0}", "test");
89+
AwaitCondition(() => _sink.Writes.Count == 1);
90+
91+
_sink.Writes.TryDequeue(out var logEvent).Should().BeTrue();
92+
logEvent.Level.Should().Be(LogEventLevel.Debug);
93+
logEvent.Exception.Should().Be(exception);
94+
}
95+
96+
[Fact]
97+
public void ShouldLogInfoLevelMessage()
98+
{
99+
var context = _loggingAdapter;
100+
101+
_sink.Clear();
102+
AwaitCondition(() => _sink.Writes.Count == 0);
103+
104+
context.Info("hi");
105+
AwaitCondition(() => _sink.Writes.Count == 1);
106+
107+
_sink.Writes.TryDequeue(out var logEvent).Should().BeTrue();
108+
logEvent.Level.Should().Be(LogEventLevel.Information);
109+
logEvent.RenderMessage().Should().Contain("hi");
110+
}
111+
112+
[Fact]
113+
public void ShouldLogInfoLevelMessageWithArgs()
114+
{
115+
var context = _loggingAdapter;
116+
117+
_sink.Clear();
118+
AwaitCondition(() => _sink.Writes.Count == 0);
119+
120+
context.Info("hi {0}", "test");
121+
AwaitCondition(() => _sink.Writes.Count == 1);
122+
123+
_sink.Writes.TryDequeue(out var logEvent).Should().BeTrue();
124+
logEvent.Level.Should().Be(LogEventLevel.Information);
125+
logEvent.RenderMessage().Should().Contain("hi \"test\"");
126+
}
127+
128+
[Fact]
129+
public void ShouldLogInfoLevelMessageWithException()
130+
{
131+
var context = _loggingAdapter;
132+
133+
_sink.Clear();
134+
AwaitCondition(() => _sink.Writes.Count == 0);
135+
136+
var exception = new Exception("BOOM!!!");
137+
context.Info(exception, "hi");
138+
AwaitCondition(() => _sink.Writes.Count == 1);
139+
140+
_sink.Writes.TryDequeue(out var logEvent).Should().BeTrue();
141+
logEvent.Level.Should().Be(LogEventLevel.Information);
142+
logEvent.Exception.Should().Be(exception);
143+
}
144+
145+
[Fact]
146+
public void ShouldLogInfoLevelMessageWithArgsAndException()
147+
{
148+
var context = _loggingAdapter;
149+
150+
_sink.Clear();
151+
AwaitCondition(() => _sink.Writes.Count == 0);
152+
153+
var exception = new Exception("BOOM!!!");
154+
context.Info(exception, "hi {0}", "test");
155+
AwaitCondition(() => _sink.Writes.Count == 1);
156+
157+
_sink.Writes.TryDequeue(out var logEvent).Should().BeTrue();
158+
logEvent.Level.Should().Be(LogEventLevel.Information);
159+
logEvent.Exception.Should().Be(exception);
160+
}
161+
162+
[Fact]
163+
public void ShouldLogWarningLevelMessage()
164+
{
165+
var context = _loggingAdapter;
166+
167+
_sink.Clear();
168+
AwaitCondition(() => _sink.Writes.Count == 0);
169+
170+
context.Warning("hi");
171+
AwaitCondition(() => _sink.Writes.Count == 1);
172+
173+
_sink.Writes.TryDequeue(out var logEvent).Should().BeTrue();
174+
logEvent.Level.Should().Be(LogEventLevel.Warning);
175+
logEvent.RenderMessage().Should().Contain("hi");
176+
}
177+
178+
[Fact]
179+
public void ShouldLogWarningLevelMessageWithArgs()
180+
{
181+
var context = _loggingAdapter;
182+
183+
_sink.Clear();
184+
AwaitCondition(() => _sink.Writes.Count == 0);
185+
186+
context.Warning("hi {0}", "test");
187+
AwaitCondition(() => _sink.Writes.Count == 1);
188+
189+
_sink.Writes.TryDequeue(out var logEvent).Should().BeTrue();
190+
logEvent.Level.Should().Be(LogEventLevel.Warning);
191+
logEvent.RenderMessage().Should().Contain("hi \"test\"");
192+
}
193+
194+
[Fact]
195+
public void ShouldLogWarningLevelMessageWithException()
196+
{
197+
var context = _loggingAdapter;
198+
199+
_sink.Clear();
200+
AwaitCondition(() => _sink.Writes.Count == 0);
201+
202+
var exception = new Exception("BOOM!!!");
203+
context.Warning(exception, "hi");
204+
AwaitCondition(() => _sink.Writes.Count == 1);
205+
206+
_sink.Writes.TryDequeue(out var logEvent).Should().BeTrue();
207+
logEvent.Level.Should().Be(LogEventLevel.Warning);
208+
logEvent.Exception.Should().Be(exception);
209+
}
210+
211+
[Fact]
212+
public void ShouldLogWarningLevelMessageWithArgsAndException()
213+
{
214+
var context = _loggingAdapter;
215+
216+
_sink.Clear();
217+
AwaitCondition(() => _sink.Writes.Count == 0);
218+
219+
var exception = new Exception("BOOM!!!");
220+
context.Warning(exception, "hi {0}", "test");
221+
AwaitCondition(() => _sink.Writes.Count == 1);
222+
223+
_sink.Writes.TryDequeue(out var logEvent).Should().BeTrue();
224+
logEvent.Level.Should().Be(LogEventLevel.Warning);
225+
logEvent.Exception.Should().Be(exception);
226+
}
227+
228+
[Fact]
229+
public void ShouldLogErrorLevelMessage()
230+
{
231+
var context = _loggingAdapter;
232+
233+
_sink.Clear();
234+
AwaitCondition(() => _sink.Writes.Count == 0);
235+
236+
context.Error("hi");
237+
AwaitCondition(() => _sink.Writes.Count == 1);
238+
239+
_sink.Writes.TryDequeue(out var logEvent).Should().BeTrue();
240+
logEvent.Level.Should().Be(LogEventLevel.Error);
241+
logEvent.RenderMessage().Should().Contain("hi");
242+
}
243+
244+
[Fact]
245+
public void ShouldLogErrorLevelMessageWithArgs()
246+
{
247+
var context = _loggingAdapter;
248+
249+
_sink.Clear();
250+
AwaitCondition(() => _sink.Writes.Count == 0);
251+
252+
context.Error("hi {0}", "test");
253+
AwaitCondition(() => _sink.Writes.Count == 1);
254+
255+
_sink.Writes.TryDequeue(out var logEvent).Should().BeTrue();
256+
logEvent.Level.Should().Be(LogEventLevel.Error);
257+
logEvent.RenderMessage().Should().Contain("hi \"test\"");
258+
}
259+
260+
[Fact]
261+
public void ShouldLogErrorLevelMessageWithException()
262+
{
263+
var context = _loggingAdapter;
264+
265+
_sink.Clear();
266+
AwaitCondition(() => _sink.Writes.Count == 0);
267+
268+
var exception = new Exception("BOOM!!!");
269+
context.Error(exception, "hi");
270+
AwaitCondition(() => _sink.Writes.Count == 1);
271+
272+
_sink.Writes.TryDequeue(out var logEvent).Should().BeTrue();
273+
logEvent.Level.Should().Be(LogEventLevel.Error);
274+
logEvent.Exception.Should().Be(exception);
275+
}
276+
277+
[Fact]
278+
public void ShouldLogErrorLevelMessageWithArgsAndException()
279+
{
280+
var context = _loggingAdapter;
281+
282+
_sink.Clear();
283+
AwaitCondition(() => _sink.Writes.Count == 0);
284+
285+
var exception = new Exception("BOOM!!!");
286+
context.Error(exception, "hi {0}", "test");
287+
AwaitCondition(() => _sink.Writes.Count == 1);
288+
289+
_sink.Writes.TryDequeue(out var logEvent).Should().BeTrue();
290+
logEvent.Level.Should().Be(LogEventLevel.Error);
291+
logEvent.Exception.Should().Be(exception);
292+
}
293+
}
294+
}

src/Akka.Logger.Serilog.Tests/TestSink.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
using System.Collections.Concurrent;
22
using Serilog.Core;
33
using Serilog.Events;
4+
using Xunit;
5+
6+
[assembly: CollectionBehavior(DisableTestParallelization = true)]
47

58
namespace Akka.Logger.Serilog.Tests
69
{

src/Akka.Logger.Serilog/SerilogLogger.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,17 +60,17 @@ private static void Handle(Error logEvent) {
6060
}
6161

6262
private static void Handle(Warning logEvent) {
63-
GetLogger(logEvent).Warning(GetFormat(logEvent.Message), GetArgs(logEvent.Message));
63+
GetLogger(logEvent).Warning(logEvent.Cause, GetFormat(logEvent.Message), GetArgs(logEvent.Message));
6464
}
6565

6666
private static void Handle(Info logEvent)
6767
{
68-
GetLogger(logEvent).Information(GetFormat(logEvent.Message), GetArgs(logEvent.Message));
68+
GetLogger(logEvent).Information(logEvent.Cause, GetFormat(logEvent.Message), GetArgs(logEvent.Message));
6969
}
7070

7171
private static void Handle(Debug logEvent)
7272
{
73-
GetLogger(logEvent).Debug(GetFormat(logEvent.Message), GetArgs(logEvent.Message));
73+
GetLogger(logEvent).Debug(logEvent.Cause, GetFormat(logEvent.Message), GetArgs(logEvent.Message));
7474
}
7575

7676
/// <summary>

src/common.props

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@
1212
</PropertyGroup>
1313
<PropertyGroup>
1414
<XunitVersion>2.4.1</XunitVersion>
15-
<TestSdkVersion>16.5.0</TestSdkVersion>
15+
<TestSdkVersion>16.6.1</TestSdkVersion>
1616
<NBenchVersion>2.0.1</NBenchVersion>
17-
<AkkaVersion>1.4.3</AkkaVersion>
17+
<AkkaVersion>1.4.8</AkkaVersion>
1818
<NetCoreTestVersion>netcoreapp3.1</NetCoreTestVersion>
1919
<NetFrameworkTestVersion>net461</NetFrameworkTestVersion>
2020
<NetStandardLibVersion>netstandard2.0</NetStandardLibVersion>

0 commit comments

Comments
 (0)