Skip to content

Commit

Permalink
Merge pull request #110 from akkadotnet/dev
Browse files Browse the repository at this point in the history
1.4.8 Release
  • Loading branch information
Aaronontheweb authored Jun 23, 2020
2 parents 3c37714 + 4eb8590 commit 5ae93b5
Show file tree
Hide file tree
Showing 5 changed files with 307 additions and 5 deletions.
5 changes: 5 additions & 0 deletions RELEASE_NOTES.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,7 @@
#### 1.4.8 June 23 2020 ####

* Updated to [Akka.NET v1.4.8](https://github.com/akkadotnet/akka.net/releases/tag/1.4.8)
* Support for exceptions logging in non-error log levels [#109](https://github.com/akkadotnet/Akka.Logger.Serilog/pull/109)

#### 1.4.3 March 27 2020 ####
* Updated Akka.Logger.Serilog to [Akka.NET v1.4.3](https://getakka.net/community/whats-new/akkadotnet-v1.4.html)
294 changes: 294 additions & 0 deletions src/Akka.Logger.Serilog.Tests/LogMessageSpecs.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,294 @@
using System;
using Akka.Actor;
using Akka.Configuration;
using Akka.Event;
using FluentAssertions;
using Serilog;
using Serilog.Events;
using Xunit;
using Xunit.Abstractions;

namespace Akka.Logger.Serilog.Tests
{
public class LogMessageSpecs : TestKit.Xunit2.TestKit
{
public static readonly Config Config = @"akka.loglevel = DEBUG
akka.loggers=[""Akka.Logger.Serilog.SerilogLogger, Akka.Logger.Serilog""]";

private readonly ILoggingAdapter _loggingAdapter;
private readonly TestSink _sink = new TestSink();

public LogMessageSpecs(ITestOutputHelper helper) : base(Config, output: helper)
{
global::Serilog.Log.Logger = new LoggerConfiguration()
.WriteTo.Sink(_sink)
.MinimumLevel.Debug()
.CreateLogger();
_loggingAdapter = Sys.Log;
}

[Fact]
public void ShouldLogDebugLevelMessage()
{
var context = _loggingAdapter;

_sink.Clear();
AwaitCondition(() => _sink.Writes.Count == 0);

context.Debug("hi");
AwaitCondition(() => _sink.Writes.Count == 1);

_sink.Writes.TryDequeue(out var logEvent).Should().BeTrue();
logEvent.Level.Should().Be(LogEventLevel.Debug);
logEvent.RenderMessage().Should().Contain("hi");
}

[Fact]
public void ShouldLogDebugLevelMessageWithArgs()
{
var context = _loggingAdapter;

_sink.Clear();
AwaitCondition(() => _sink.Writes.Count == 0);

context.Debug("hi {0}", "test");
AwaitCondition(() => _sink.Writes.Count == 1);

_sink.Writes.TryDequeue(out var logEvent).Should().BeTrue();
logEvent.Level.Should().Be(LogEventLevel.Debug);
logEvent.RenderMessage().Should().Contain("hi \"test\"");
}

[Fact]
public void ShouldLogDebugLevelMessageWithException()
{
var context = _loggingAdapter;

_sink.Clear();
AwaitCondition(() => _sink.Writes.Count == 0);

var exception = new Exception("BOOM!!!");
context.Debug(exception, "hi");
AwaitCondition(() => _sink.Writes.Count == 1);

_sink.Writes.TryDequeue(out var logEvent).Should().BeTrue();
logEvent.Level.Should().Be(LogEventLevel.Debug);
logEvent.Exception.Should().Be(exception);
}

[Fact]
public void ShouldLogDebugLevelMessageWithArgsAndException()
{
var context = _loggingAdapter;

_sink.Clear();
AwaitCondition(() => _sink.Writes.Count == 0);

var exception = new Exception("BOOM!!!");
context.Debug(exception, "hi {0}", "test");
AwaitCondition(() => _sink.Writes.Count == 1);

_sink.Writes.TryDequeue(out var logEvent).Should().BeTrue();
logEvent.Level.Should().Be(LogEventLevel.Debug);
logEvent.Exception.Should().Be(exception);
}

[Fact]
public void ShouldLogInfoLevelMessage()
{
var context = _loggingAdapter;

_sink.Clear();
AwaitCondition(() => _sink.Writes.Count == 0);

context.Info("hi");
AwaitCondition(() => _sink.Writes.Count == 1);

_sink.Writes.TryDequeue(out var logEvent).Should().BeTrue();
logEvent.Level.Should().Be(LogEventLevel.Information);
logEvent.RenderMessage().Should().Contain("hi");
}

[Fact]
public void ShouldLogInfoLevelMessageWithArgs()
{
var context = _loggingAdapter;

_sink.Clear();
AwaitCondition(() => _sink.Writes.Count == 0);

context.Info("hi {0}", "test");
AwaitCondition(() => _sink.Writes.Count == 1);

_sink.Writes.TryDequeue(out var logEvent).Should().BeTrue();
logEvent.Level.Should().Be(LogEventLevel.Information);
logEvent.RenderMessage().Should().Contain("hi \"test\"");
}

[Fact]
public void ShouldLogInfoLevelMessageWithException()
{
var context = _loggingAdapter;

_sink.Clear();
AwaitCondition(() => _sink.Writes.Count == 0);

var exception = new Exception("BOOM!!!");
context.Info(exception, "hi");
AwaitCondition(() => _sink.Writes.Count == 1);

_sink.Writes.TryDequeue(out var logEvent).Should().BeTrue();
logEvent.Level.Should().Be(LogEventLevel.Information);
logEvent.Exception.Should().Be(exception);
}

[Fact]
public void ShouldLogInfoLevelMessageWithArgsAndException()
{
var context = _loggingAdapter;

_sink.Clear();
AwaitCondition(() => _sink.Writes.Count == 0);

var exception = new Exception("BOOM!!!");
context.Info(exception, "hi {0}", "test");
AwaitCondition(() => _sink.Writes.Count == 1);

_sink.Writes.TryDequeue(out var logEvent).Should().BeTrue();
logEvent.Level.Should().Be(LogEventLevel.Information);
logEvent.Exception.Should().Be(exception);
}

[Fact]
public void ShouldLogWarningLevelMessage()
{
var context = _loggingAdapter;

_sink.Clear();
AwaitCondition(() => _sink.Writes.Count == 0);

context.Warning("hi");
AwaitCondition(() => _sink.Writes.Count == 1);

_sink.Writes.TryDequeue(out var logEvent).Should().BeTrue();
logEvent.Level.Should().Be(LogEventLevel.Warning);
logEvent.RenderMessage().Should().Contain("hi");
}

[Fact]
public void ShouldLogWarningLevelMessageWithArgs()
{
var context = _loggingAdapter;

_sink.Clear();
AwaitCondition(() => _sink.Writes.Count == 0);

context.Warning("hi {0}", "test");
AwaitCondition(() => _sink.Writes.Count == 1);

_sink.Writes.TryDequeue(out var logEvent).Should().BeTrue();
logEvent.Level.Should().Be(LogEventLevel.Warning);
logEvent.RenderMessage().Should().Contain("hi \"test\"");
}

[Fact]
public void ShouldLogWarningLevelMessageWithException()
{
var context = _loggingAdapter;

_sink.Clear();
AwaitCondition(() => _sink.Writes.Count == 0);

var exception = new Exception("BOOM!!!");
context.Warning(exception, "hi");
AwaitCondition(() => _sink.Writes.Count == 1);

_sink.Writes.TryDequeue(out var logEvent).Should().BeTrue();
logEvent.Level.Should().Be(LogEventLevel.Warning);
logEvent.Exception.Should().Be(exception);
}

[Fact]
public void ShouldLogWarningLevelMessageWithArgsAndException()
{
var context = _loggingAdapter;

_sink.Clear();
AwaitCondition(() => _sink.Writes.Count == 0);

var exception = new Exception("BOOM!!!");
context.Warning(exception, "hi {0}", "test");
AwaitCondition(() => _sink.Writes.Count == 1);

_sink.Writes.TryDequeue(out var logEvent).Should().BeTrue();
logEvent.Level.Should().Be(LogEventLevel.Warning);
logEvent.Exception.Should().Be(exception);
}

[Fact]
public void ShouldLogErrorLevelMessage()
{
var context = _loggingAdapter;

_sink.Clear();
AwaitCondition(() => _sink.Writes.Count == 0);

context.Error("hi");
AwaitCondition(() => _sink.Writes.Count == 1);

_sink.Writes.TryDequeue(out var logEvent).Should().BeTrue();
logEvent.Level.Should().Be(LogEventLevel.Error);
logEvent.RenderMessage().Should().Contain("hi");
}

[Fact]
public void ShouldLogErrorLevelMessageWithArgs()
{
var context = _loggingAdapter;

_sink.Clear();
AwaitCondition(() => _sink.Writes.Count == 0);

context.Error("hi {0}", "test");
AwaitCondition(() => _sink.Writes.Count == 1);

_sink.Writes.TryDequeue(out var logEvent).Should().BeTrue();
logEvent.Level.Should().Be(LogEventLevel.Error);
logEvent.RenderMessage().Should().Contain("hi \"test\"");
}

[Fact]
public void ShouldLogErrorLevelMessageWithException()
{
var context = _loggingAdapter;

_sink.Clear();
AwaitCondition(() => _sink.Writes.Count == 0);

var exception = new Exception("BOOM!!!");
context.Error(exception, "hi");
AwaitCondition(() => _sink.Writes.Count == 1);

_sink.Writes.TryDequeue(out var logEvent).Should().BeTrue();
logEvent.Level.Should().Be(LogEventLevel.Error);
logEvent.Exception.Should().Be(exception);
}

[Fact]
public void ShouldLogErrorLevelMessageWithArgsAndException()
{
var context = _loggingAdapter;

_sink.Clear();
AwaitCondition(() => _sink.Writes.Count == 0);

var exception = new Exception("BOOM!!!");
context.Error(exception, "hi {0}", "test");
AwaitCondition(() => _sink.Writes.Count == 1);

_sink.Writes.TryDequeue(out var logEvent).Should().BeTrue();
logEvent.Level.Should().Be(LogEventLevel.Error);
logEvent.Exception.Should().Be(exception);
}
}
}
3 changes: 3 additions & 0 deletions src/Akka.Logger.Serilog.Tests/TestSink.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
using System.Collections.Concurrent;
using Serilog.Core;
using Serilog.Events;
using Xunit;

[assembly: CollectionBehavior(DisableTestParallelization = true)]

namespace Akka.Logger.Serilog.Tests
{
Expand Down
6 changes: 3 additions & 3 deletions src/Akka.Logger.Serilog/SerilogLogger.cs
Original file line number Diff line number Diff line change
Expand Up @@ -60,17 +60,17 @@ private static void Handle(Error logEvent) {
}

private static void Handle(Warning logEvent) {
GetLogger(logEvent).Warning(GetFormat(logEvent.Message), GetArgs(logEvent.Message));
GetLogger(logEvent).Warning(logEvent.Cause, GetFormat(logEvent.Message), GetArgs(logEvent.Message));
}

private static void Handle(Info logEvent)
{
GetLogger(logEvent).Information(GetFormat(logEvent.Message), GetArgs(logEvent.Message));
GetLogger(logEvent).Information(logEvent.Cause, GetFormat(logEvent.Message), GetArgs(logEvent.Message));
}

private static void Handle(Debug logEvent)
{
GetLogger(logEvent).Debug(GetFormat(logEvent.Message), GetArgs(logEvent.Message));
GetLogger(logEvent).Debug(logEvent.Cause, GetFormat(logEvent.Message), GetArgs(logEvent.Message));
}

/// <summary>
Expand Down
4 changes: 2 additions & 2 deletions src/common.props
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@
</PropertyGroup>
<PropertyGroup>
<XunitVersion>2.4.1</XunitVersion>
<TestSdkVersion>16.5.0</TestSdkVersion>
<TestSdkVersion>16.6.1</TestSdkVersion>
<NBenchVersion>2.0.1</NBenchVersion>
<AkkaVersion>1.4.3</AkkaVersion>
<AkkaVersion>1.4.8</AkkaVersion>
<NetCoreTestVersion>netcoreapp3.1</NetCoreTestVersion>
<NetFrameworkTestVersion>net461</NetFrameworkTestVersion>
<NetStandardLibVersion>netstandard2.0</NetStandardLibVersion>
Expand Down

0 comments on commit 5ae93b5

Please sign in to comment.