Skip to content

Commit

Permalink
fix: deprecate logger core package (#264)
Browse files Browse the repository at this point in the history
  • Loading branch information
stijnmoreels authored Jan 29, 2025
1 parent 4573107 commit d1c4139
Show file tree
Hide file tree
Showing 14 changed files with 91 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@
<Company>Arcus</Company>
<Description>Provides logging capabilities during Arcus testing</Description>
<Copyright>Copyright (c) Arcus</Copyright>
<GeneratePackageOnBuild>false</GeneratePackageOnBuild>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<GenerateDocumentationFile>false</GenerateDocumentationFile>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
<WarningsNotAsErrors>$(WarningsNotAsErrors);NU1901;NU1902;NU1903;NU1904</WarningsNotAsErrors>
<WarningsNotAsErrors>$(WarningsNotAsErrors);NU1901;NU1902;NU1903;NU1904;CS6018</WarningsNotAsErrors>
</PropertyGroup>

<ItemGroup>
Expand Down
3 changes: 3 additions & 0 deletions src/Arcus.Testing.Logging.Core/CustomLoggerProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ namespace Arcus.Testing
/// <summary>
/// Custom <see cref="ILoggerProvider"/> that creates a custom <see cref="ILogger"/> provider.
/// </summary>
#pragma warning disable S1133
[Obsolete("Will be removed in v2.0, use the specific logging packages (Xunit, NUnit, MSTest) instead")]
#pragma warning restore
public class CustomLoggerProvider : ILoggerProvider
{
private readonly ILogger _logger;
Expand Down
6 changes: 4 additions & 2 deletions src/Arcus.Testing.Logging.Core/InMemoryLogSink.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,13 @@ namespace Arcus.Testing
/// <summary>
/// Represents a logging sink that collects the emitted log events in-memory.
/// </summary>
#pragma warning disable S1133
[Obsolete("Arcus.Testing.Logging.Core will stop supporting Serilog by default, please implement Serilog sinks yourself as this sink will be removed in v2.0")]
#pragma warning restore
public class InMemoryLogSink : ILogEventSink
{
private readonly ConcurrentQueue<LogEvent> _logEmits = new ConcurrentQueue<LogEvent>();

/// <summary>
/// Gets the current log emits available on the sink.
/// </summary>
Expand All @@ -24,7 +26,7 @@ public class InMemoryLogSink : ILogEventSink
/// Gets the current messages of the log emits available on the sink.
/// </summary>
public IEnumerable<string> CurrentLogMessages => CurrentLogEmits.Select(emit => emit.RenderMessage());

/// <summary>
/// Emit the provided log event to the sink.
/// </summary>
Expand Down
3 changes: 3 additions & 0 deletions src/Arcus.Testing.Logging.Core/InMemoryLogger.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ namespace Arcus.Testing
/// <summary>
/// Spy (stub) <see cref="ILogger"/> implementation to track the logged messages in-memory.
/// </summary>
#pragma warning disable S1133
[Obsolete("Will be removed in v2.0, use the specific logging packages (Xunit, NUnit, MSTest) instead")]
#pragma warning restore
public class InMemoryLogger : ILogger
{
private readonly ConcurrentQueue<LogEntry> _entries = new ConcurrentQueue<LogEntry>();
Expand Down
6 changes: 5 additions & 1 deletion src/Arcus.Testing.Logging.Core/InMemoryLoggerT.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
using Microsoft.Extensions.Logging;
using System;
using Microsoft.Extensions.Logging;

namespace Arcus.Testing
{
/// <summary>
/// Spy (stub) <see cref="ILogger{TCategoryName}"/> implementation to track the logged messages in-memory.
/// </summary>
/// <typeparam name="T">The type who's name is used for the logger category name.</typeparam>
#pragma warning disable S1133
[Obsolete("Will be removed in v2.0, use the specific logging packages (Xunit, NUnit, MSTest) instead")]
#pragma warning restore
public class InMemoryLogger<T> : InMemoryLogger, ILogger<T>
{
}
Expand Down
3 changes: 3 additions & 0 deletions src/Arcus.Testing.Logging.Core/LogEntry.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ namespace Arcus.Testing
/// <summary>
/// Represents a logged message by a <see cref="ILogger"/> instance.
/// </summary>
#pragma warning disable S1133
[Obsolete("Will be removed in v2.0, use the specific logging packages (Xunit, NUnit, MSTest) instead")]
#pragma warning restore
public class LogEntry
{
/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,9 @@
</ItemGroup>

<ItemGroup>
<!-- TODO: reference will be removed in v2.0 -->
<ProjectReference Include="..\Arcus.Testing.Logging.Core\Arcus.Testing.Logging.Core.csproj" />
<!-- TODO: reference will be removed in v2.0 -->
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,27 @@ public static ILoggingBuilder AddMSTestLogging(this ILoggingBuilder builder, Tes
ArgumentNullException.ThrowIfNull(builder);
ArgumentNullException.ThrowIfNull(testContext);

var logger = new MSTestLogger(testContext);
var provider = new CustomLoggerProvider(logger);

var provider = new MSTestLoggerProvider(testContext);
return builder.AddProvider(provider);
}

private sealed class MSTestLoggerProvider : ILoggerProvider
{
private readonly ILogger _logger;

public MSTestLoggerProvider(TestContext context)
{
_logger = new MSTestLogger(context);
}

public ILogger CreateLogger(string categoryName)
{
return _logger;
}

public void Dispose()
{
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@ public static class LoggerSinkConfigurationExtensions
/// <param name="config">The Serilog sink configuration where the NUnit test logging will be added.</param>
/// <param name="testContext">The MSTest test writer to write custom test output.</param>
/// <exception cref="ArgumentNullException">Thrown when the <paramref name="config"/> or <paramref name="testContext"/> is <c>null</c>.</exception>
#pragma warning disable S1133
[Obsolete("Arcus.Testing.Logging.MSTest will stop supporting Serilog by default, please implement Serilog sinks yourself as this extension will be removed in v2.0")]
#pragma warning restore
public static LoggerConfiguration MSTestLogging(this LoggerSinkConfiguration config, TestContext testContext)
{
if (config is null)
Expand Down
2 changes: 2 additions & 0 deletions src/Arcus.Testing.Logging.MSTest/MSTestLogEventSink.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ namespace Arcus.Testing
/// <summary>
/// <see cref="ILogEventSink"/> representation of an <see cref="MSTestLogger"/> instance.
/// </summary>
#pragma warning disable S1133
[Obsolete("Arcus.Testing.Logging.MSTest will stop supporting Serilog by default, please implement Serilog sinks yourself as this sink will be removed in v2.0")]
#pragma warning restore
public class MSTestLogEventSink : ILogEventSink
{
private readonly TestContext _context;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@
</ItemGroup>

<ItemGroup>
<!-- TODO: reference will be removed in v2.0 -->
<ProjectReference Include="..\Arcus.Testing.Logging.Core\Arcus.Testing.Logging.Core.csproj" />
</ItemGroup>
<!-- TODO: reference will be removed in v2.0 --> </ItemGroup>

</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public static ILoggingBuilder AddNUnitTestLogging(this ILoggingBuilder builder,
ArgumentNullException.ThrowIfNull(outputWriter);

var logger = new NUnitTestLogger(outputWriter);
var provider = new CustomLoggerProvider(logger);
var provider = new NUnitLoggerProvider(logger);

return builder.AddProvider(provider);
}
Expand All @@ -41,9 +41,28 @@ public static ILoggingBuilder AddNUnitTestLogging(this ILoggingBuilder builder,
ArgumentNullException.ThrowIfNull(outputWriter);

var logger = new NUnitTestLogger(outputWriter, errorWriter);
var provider = new CustomLoggerProvider(logger);
var provider = new NUnitLoggerProvider(logger);

return builder.AddProvider(provider);
}

private sealed class NUnitLoggerProvider : ILoggerProvider
{
private readonly NUnitTestLogger _logger;

public NUnitLoggerProvider(NUnitTestLogger logger)
{
_logger = logger;
}

public ILogger CreateLogger(string categoryName)
{
return _logger;
}

public void Dispose()
{
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@
</ItemGroup>

<ItemGroup>
<!-- TODO: reference will be removed in v2.0 -->
<ProjectReference Include="..\Arcus.Testing.Logging.Core\Arcus.Testing.Logging.Core.csproj" />
</ItemGroup>
<!-- TODO: reference will be removed in v2.0 --> </ItemGroup>

</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,27 @@ public static ILoggingBuilder AddXunitTestLogging(this ILoggingBuilder builder,
ArgumentNullException.ThrowIfNull(builder);
ArgumentNullException.ThrowIfNull(outputWriter);

var logger = new XunitTestLogger(outputWriter);
var provider = new CustomLoggerProvider(logger);

var provider = new XunitLoggerProvider(outputWriter);
return builder.AddProvider(provider);
}

private sealed class XunitLoggerProvider : ILoggerProvider
{
private readonly ILogger _logger;

public XunitLoggerProvider(ITestOutputHelper outputWriter)
{
_logger = new XunitTestLogger(outputWriter);
}

public ILogger CreateLogger(string categoryName)
{
return _logger;
}

public void Dispose()
{
}
}
}
}

0 comments on commit d1c4139

Please sign in to comment.