C3D.Extensions.Logging.Xunit
0.2.14
See the version list below for details.
dotnet add package C3D.Extensions.Logging.Xunit --version 0.2.14
NuGet\Install-Package C3D.Extensions.Logging.Xunit -Version 0.2.14
<PackageReference Include="C3D.Extensions.Logging.Xunit" Version="0.2.14" />
paket add C3D.Extensions.Logging.Xunit --version 0.2.14
#r "nuget: C3D.Extensions.Logging.Xunit, 0.2.14"
// Install C3D.Extensions.Logging.Xunit as a Cake Addin #addin nuget:?package=C3D.Extensions.Logging.Xunit&version=0.2.14 // Install C3D.Extensions.Logging.Xunit as a Cake Tool #tool nuget:?package=C3D.Extensions.Logging.Xunit&version=0.2.14
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=>{
});
N.B. This will add the output
object as a singleton to the ILoggingBuilder
services.
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.
Utilities
As you may want to check the logged output for content in your tests (either for something existing or not existing), there are 2 utility classes provided.
LoggingMessageSink
which implementsIMessageSink
LoggingTestOutputHelper
which implementsITestOutputHelper
These both have a ClearMessages
function (which may be required in a fixture to ensure output from one test does not affect another), and a Messages
property.
Examples of how to use these can be found in the unit tests at CZEMacLeod/C3D.Extensions.Logging.
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 is compatible. 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.Bcl.TimeProvider (>= 8.0.1)
- Microsoft.Extensions.Logging.Abstractions (>= 8.0.1)
- Microsoft.Extensions.Logging.Configuration (>= 8.0.0)
- Microsoft.Extensions.Options.ConfigurationExtensions (>= 8.0.0)
- System.Collections.Immutable (>= 8.0.0)
- xunit.abstractions (>= 2.0.3)
- xunit.extensibility.execution (>= 2.9.0)
-
.NETStandard 2.0
- Microsoft.Bcl.TimeProvider (>= 8.0.1)
- Microsoft.Extensions.Logging.Abstractions (>= 8.0.1)
- Microsoft.Extensions.Logging.Configuration (>= 8.0.0)
- Microsoft.Extensions.Options.ConfigurationExtensions (>= 8.0.0)
- System.Collections.Immutable (>= 8.0.0)
- xunit.abstractions (>= 2.0.3)
- xunit.extensibility.execution (>= 2.9.0)
-
.NETStandard 2.1
- Microsoft.Bcl.TimeProvider (>= 8.0.1)
- Microsoft.Extensions.Logging.Abstractions (>= 8.0.1)
- Microsoft.Extensions.Logging.Configuration (>= 8.0.0)
- Microsoft.Extensions.Options.ConfigurationExtensions (>= 8.0.0)
- System.Collections.Immutable (>= 8.0.0)
- xunit.abstractions (>= 2.0.3)
- xunit.extensibility.execution (>= 2.9.0)
-
net6.0
- Microsoft.Bcl.TimeProvider (>= 8.0.1)
- Microsoft.Extensions.Logging.Abstractions (>= 8.0.1)
- Microsoft.Extensions.Logging.Configuration (>= 8.0.0)
- Microsoft.Extensions.Options.ConfigurationExtensions (>= 8.0.0)
- System.Collections.Immutable (>= 8.0.0)
- xunit.abstractions (>= 2.0.3)
- xunit.extensibility.execution (>= 2.9.0)
-
net7.0
- Microsoft.Bcl.TimeProvider (>= 8.0.1)
- Microsoft.Extensions.Logging.Abstractions (>= 8.0.1)
- Microsoft.Extensions.Logging.Configuration (>= 8.0.0)
- Microsoft.Extensions.Options.ConfigurationExtensions (>= 8.0.0)
- System.Collections.Immutable (>= 8.0.0)
- xunit.abstractions (>= 2.0.3)
- xunit.extensibility.execution (>= 2.9.0)
-
net8.0
- Microsoft.Bcl.TimeProvider (>= 8.0.1)
- Microsoft.Extensions.Logging.Abstractions (>= 8.0.1)
- Microsoft.Extensions.Logging.Configuration (>= 8.0.0)
- Microsoft.Extensions.Options.ConfigurationExtensions (>= 8.0.0)
- System.Collections.Immutable (>= 8.0.0)
- xunit.abstractions (>= 2.0.3)
- xunit.extensibility.execution (>= 2.9.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.