C3D.Extensions.Logging.Xunit
0.1.17
See the version list below for details.
dotnet add package C3D.Extensions.Logging.Xunit --version 0.1.17
NuGet\Install-Package C3D.Extensions.Logging.Xunit -Version 0.1.17
<PackageReference Include="C3D.Extensions.Logging.Xunit" Version="0.1.17" />
paket add C3D.Extensions.Logging.Xunit --version 0.1.17
#r "nuget: C3D.Extensions.Logging.Xunit, 0.1.17"
// Install C3D.Extensions.Logging.Xunit as a Cake Addin #addin nuget:?package=C3D.Extensions.Logging.Xunit&version=0.1.17 // Install C3D.Extensions.Logging.Xunit as a Cake Tool #tool nuget:?package=C3D.Extensions.Logging.Xunit&version=0.1.17
C3D.Extensions.Logging.Xunit
An implementation of Microsoft.Extensions.Logging
Loggers wrapping xunit output types.
This allows you to capture logging output when using dotnet test
etc.
It can be injected into services under test, or used as a provider in DI.
It supports some minor configuration which can be added via the normal configuration sources, such as appsettings.json, usersecrets etc.
Configuration
{
"Logging": {
"Xunit": {
"MinLevel": "Trace",
"UseOffset": true,
"LogLevel": {
"Default": "Trace"
}
}
}
}
Usage
Dependency Injection
services
.AddSingleton(output)
.AddLogging(logging => logging
.ClearProviders()
.SetMinimumLevel(LogLevel.Debug)
.AddXunit());
Here output
can be either ITestOutputHelper
or IMessageSink
, depending on whether you are using this from a unit test, or a class fixture.
Alternatively, you can explicitly add the output, and/or setup the logging configuration inside the AddXunit
extension method.
logging
.AddXunit(output, config=>{
});
Direct injection
private readonly ITestOutputHelper output;
ILogger<ClassUnderTest> log = output.CreateLogger<ClassUnderTest>();
\\ Assuming that the constuctor of ClassUnderTest takes an ILogger or ILogger<ClassUnderTest>
var sut = new ClassUnderTest(log);
\\ perform tests with logging...
Here the ILogger creation line might replace something like
ILogger<ClassUnderTest> log = Microsoft.Extensions.Logging.Abstractions.NullLoggerFactory.Instance.CreateLogger<ClassUnderTest>();
Factory
You can also create a LoggerFactory if you need to using something like
private readonly ITestOutputHelper output;
var loggerFactory = LoggerFactory.Create(builder => builder.AddXunit(output));
Fixtures
The same mechanisms used in tests based on injecting ITestOutputHelper
into the test class, can be used in fixtures.
However, in fixtures you inject IMessageSink
. The same extension methods are available for both interfaces.
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net5.0 was computed. net5.0-windows was computed. net6.0 is compatible. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 is compatible. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. |
.NET Core | netcoreapp2.0 was computed. netcoreapp2.1 was computed. netcoreapp2.2 was computed. netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
.NET Standard | netstandard2.0 is compatible. netstandard2.1 is compatible. |
.NET Framework | net461 was computed. net462 is compatible. net463 was computed. net47 was computed. net471 was computed. net472 was computed. net48 was computed. net481 was computed. |
MonoAndroid | monoandroid was computed. |
MonoMac | monomac was computed. |
MonoTouch | monotouch was computed. |
Tizen | tizen40 was computed. tizen60 was computed. |
Xamarin.iOS | xamarinios was computed. |
Xamarin.Mac | xamarinmac was computed. |
Xamarin.TVOS | xamarintvos was computed. |
Xamarin.WatchOS | xamarinwatchos was computed. |
-
.NETFramework 4.6.2
- Microsoft.Extensions.Logging.Configuration (>= 6.0.0)
- Microsoft.Extensions.Options.ConfigurationExtensions (>= 6.0.0)
- xunit.abstractions (>= 2.0.3)
- xunit.extensibility.execution (>= 2.5.0)
-
.NETStandard 2.0
- Microsoft.Extensions.Logging.Configuration (>= 6.0.0)
- Microsoft.Extensions.Options.ConfigurationExtensions (>= 6.0.0)
- xunit.abstractions (>= 2.0.3)
- xunit.extensibility.execution (>= 2.5.0)
-
.NETStandard 2.1
- Microsoft.Extensions.Logging.Configuration (>= 6.0.0)
- Microsoft.Extensions.Options.ConfigurationExtensions (>= 6.0.0)
- xunit.abstractions (>= 2.0.3)
- xunit.extensibility.execution (>= 2.5.0)
-
net6.0
- Microsoft.Extensions.Logging.Configuration (>= 6.0.0)
- Microsoft.Extensions.Options.ConfigurationExtensions (>= 6.0.0)
- xunit.abstractions (>= 2.0.3)
- xunit.extensibility.execution (>= 2.5.0)
-
net7.0
- Microsoft.Extensions.Logging.Abstractions (>= 7.0.0)
- Microsoft.Extensions.Logging.Configuration (>= 6.0.0)
- Microsoft.Extensions.Options.ConfigurationExtensions (>= 6.0.0)
- xunit.abstractions (>= 2.0.3)
- xunit.extensibility.execution (>= 2.5.0)
NuGet packages (1)
Showing the top 1 NuGet packages that depend on C3D.Extensions.Logging.Xunit:
Package | Downloads |
---|---|
C3D.Extensions.Playwright.AspNetCore.Xunit
Assembly Version: 0.1.0.0 File Version: 0.1.40.31910 Informational Version: 0.1.40+7ca679ce39 Build Configuration: Release |
GitHub repositories
This package is not used by any popular GitHub repositories.