Releases: martincostello/xunit-logging
v0.5.0
Add support for xunit v3 🆕✨
Xunit v3 contains many major architectural changes which means the same package that supports logging for xunit v2 cannot be used with xunit v3.
The equivalent NuGet package to support logging for xunit v3 is the new MartinCostello.Logging.XUnit.v3 package.
To migrate usage of MartinCostello.Logging.XUnit
to MartinCostello.Logging.XUnit.v3
for xunit v3:
-
Follow the relevant steps to migrate any test projects from xunit v2 to v3. The most relevant change in xunit v3 for this library is that the
ITestOutputHelper
type has moved from theXunit.Abstractions
namespace toXunit
. -
Change any package references from
MartinCostello.Logging.XUnit
toMartinCostello.Logging.XUnit.v3
.- <PackageReference Include="MartinCostello.Logging.XUnit" Version="0.5.0" /> + <PackageReference Include="MartinCostello.Logging.XUnit.v3" Version="0.5.0" />
Support for xunit v2 continues with the existing MartinCostello.Logging.XUnit package.
What's Changed
- Pool loggers by @martincostello in #765
- Update to .NET 9 by @martincostello in #566
- Support xunit v3 by @martincostello in #804
- Add xunit v3 migration guide by @martincostello in #805
Full Changelog: v0.4.0...v0.5.0
v0.4.0
What's Changed
- Add PackageReadmeFile by @martincostello in #388
- .NET 8 preparation by @martincostello in #421
- Use SHA-256 for checksums by @martincostello in #500
- Update to .NET 8 by @martincostello in #412
- Add net8.0 target by @martincostello in #560
- Attest artifacts by @martincostello in #634
- Attest packages by @martincostello in #635
- Generate SBOM by @martincostello in #650
- Add dedicated package README by @martincostello in #665
New Contributors
Full Changelog: v0.3.0...v0.4.0
v0.3.0
v0.2.1
MartinCostello.Logging.XUnit v0.2.0
MartinCostello.Logging.XUnit v0.2.0
Changed
Installation
To install the library from NuGet using the .NET SDK run:
dotnet add package MartinCostello.Logging.XUnit --version 0.2.0
Contributors
MartinCostello.Logging.XUnit v0.1.2
MartinCostello.Logging.XUnit v0.1.2
Changed
Installation
To install the library from NuGet using the .NET SDK run:
dotnet add package MartinCostello.Logging.XUnit --version 0.1.2
Contributors
MartinCostello.Logging.XUnit v0.1.1
MartinCostello.Logging.XUnit v0.1.1
Changed
- Detect logging of
IEnumerable<KeyValuePair<string, object>>
scopes. (#214, #215) Thanks @gkinsman! - Update to latest recommended NuGet package publishing standards (
snpkg
symbols, deterministic builds etc.). - Update samples to latest recommended usage patterns and .NET 5.0.
Installation
To install the library from NuGet using the .NET SDK run:
dotnet add package MartinCostello.Logging.XUnit --version 0.1.1
Contributors
MartinCostello.Logging.XUnit v0.1.0
MartinCostello.Logging.XUnit v0.1.0
Introduction
MartinCostello.Logging.XUnit
provides extensions to hook into the ILogger
infrastructure to output logs from your xunit tests to the test output.
Installation
To install the library from NuGet using the .NET SDK run:
dotnet add package MartinCostello.Logging.XUnit --version 0.1.0
Usage
using System;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using Xunit;
using Xunit.Abstractions;
namespace MyApp.Calculator
{
public class CalculatorTests
{
public CalculatorTests(ITestOutputHelper outputHelper)
{
OutputHelper = outputHelper;
}
private ITestOutputHelper OutputHelper { get; }
[Fact]
public void Calculator_Sums_Two_Integers()
{
// Arrange
var services = new ServiceCollection()
.AddLogging((builder) => builder.AddXUnit(OutputHelper))
.AddSingleton<Calculator>();
var calculator = services
.BuildServiceProvider()
.GetRequiredService<Calculator>();
// Act
int actual = calculator.Sum(1, 2);
// Assert
Assert.AreEqual(3, actual);
}
}
public sealed class Calculator
{
private readonly ILogger _logger;
public Calculator(ILogger<Calculator> logger)
{
_logger = logger;
}
public int Sum(int x, int y)
{
int sum = x + y;
_logger.LogInformation("The sum of {x} and {y} is {sum}.", x, y, sum);
return sum;
}
}
}