Skip to content
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,4 @@ updates:
- dependency-name: Microsoft.Extensions.Logging
- dependency-name: xunit.abstractions
- dependency-name: xunit.extensibility.execution
- dependency-name: xunit.v3.extensibility.core
9 changes: 2 additions & 7 deletions Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@
<SymbolPackageFormat>snupkg</SymbolPackageFormat>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
<UseArtifactsOutput>true</UseArtifactsOutput>
<AssemblyVersion>0.4.0.0</AssemblyVersion>
<VersionPrefix>0.4.1</VersionPrefix>
<AssemblyVersion>0.5.0.0</AssemblyVersion>
<VersionPrefix>0.5.0</VersionPrefix>
</PropertyGroup>
<PropertyGroup Condition=" '$(GITHUB_ACTIONS)' != '' ">
<VersionSuffix Condition=" '$(VersionSuffix)' == '' AND '$(GITHUB_HEAD_REF)' == '' ">beta.$(GITHUB_RUN_NUMBER)</VersionSuffix>
Expand Down Expand Up @@ -73,9 +73,4 @@
<ItemGroup>
<Using Include="System.Globalization" />
</ItemGroup>
<ItemGroup Condition=" '$(IsTestProject)' == 'true' ">
<Using Include="Shouldly" />
<Using Include="Xunit" />
<Using Include="Xunit.Abstractions" />
</ItemGroup>
</Project>
2 changes: 2 additions & 0 deletions Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
<PackageVersion Include="xunit.abstractions" Version="2.0.3" />
<PackageVersion Include="xunit.extensibility.execution" Version="2.9.2" />
<PackageVersion Include="xunit.runner.visualstudio" Version="3.0.0" />
<PackageVersion Include="xunit.v3" Version="1.0.0" />
<PackageVersion Include="xunit.v3.extensibility.core" Version="1.0.0" />
</ItemGroup>
<ItemGroup Condition=" '$(IsTestProject)' == 'true' ">
<PackageReference Include="coverlet.msbuild" PrivateAssets="All" />
Expand Down
14 changes: 14 additions & 0 deletions Logging.XUnit.sln
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,10 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "workflows", "workflows", "{
.github\workflows\release.yml = .github\workflows\release.yml
EndProjectSection
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MartinCostello.Logging.XUnit.v3", "src\Logging.XUnit.v3\MartinCostello.Logging.XUnit.v3.csproj", "{2C161BB9-E6D0-4561-9D98-EDEAA8A49C5E}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MartinCostello.Logging.XUnit.v3.Tests", "tests\Logging.XUnit.v3.Tests\MartinCostello.Logging.XUnit.v3.Tests.csproj", "{828C7199-ADF2-456C-8BBB-4A73A329D017}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand All @@ -85,6 +89,14 @@ Global
{B690F271-3B5D-4975-A607-AED1768595B1}.Debug|Any CPU.Build.0 = Debug|Any CPU
{B690F271-3B5D-4975-A607-AED1768595B1}.Release|Any CPU.ActiveCfg = Release|Any CPU
{B690F271-3B5D-4975-A607-AED1768595B1}.Release|Any CPU.Build.0 = Release|Any CPU
{2C161BB9-E6D0-4561-9D98-EDEAA8A49C5E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{2C161BB9-E6D0-4561-9D98-EDEAA8A49C5E}.Debug|Any CPU.Build.0 = Debug|Any CPU
{2C161BB9-E6D0-4561-9D98-EDEAA8A49C5E}.Release|Any CPU.ActiveCfg = Release|Any CPU
{2C161BB9-E6D0-4561-9D98-EDEAA8A49C5E}.Release|Any CPU.Build.0 = Release|Any CPU
{828C7199-ADF2-456C-8BBB-4A73A329D017}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{828C7199-ADF2-456C-8BBB-4A73A329D017}.Debug|Any CPU.Build.0 = Debug|Any CPU
{828C7199-ADF2-456C-8BBB-4A73A329D017}.Release|Any CPU.ActiveCfg = Release|Any CPU
{828C7199-ADF2-456C-8BBB-4A73A329D017}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand All @@ -97,6 +109,8 @@ Global
{BB443063-F523-474D-83E3-D5FF5B075950} = {2684B19D-7D49-4099-8BD2-4D281455EB29}
{B690F271-3B5D-4975-A607-AED1768595B1} = {278BCCB1-39B2-46DB-9395-7F85995A6132}
{7764A046-DEE7-4D88-83E2-537DB7767123} = {D0426D09-1FF8-4E1F-A9AF-38DDEE5D7CCA}
{2C161BB9-E6D0-4561-9D98-EDEAA8A49C5E} = {2684B19D-7D49-4099-8BD2-4D281455EB29}
{828C7199-ADF2-456C-8BBB-4A73A329D017} = {278BCCB1-39B2-46DB-9395-7F85995A6132}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {3B9E157C-5E92-4357-B233-281B4530EABD}
Expand Down
12 changes: 9 additions & 3 deletions build.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,14 @@ $ProgressPreference = "SilentlyContinue"
$solutionPath = $PSScriptRoot
$sdkFile = Join-Path $solutionPath "global.json"

$libraryProject = Join-Path $solutionPath "src" "Logging.XUnit" "MartinCostello.Logging.XUnit.csproj"
$libraryProjects = @(
(Join-Path $solutionPath "src" "Logging.XUnit" "MartinCostello.Logging.XUnit.csproj")
(Join-Path $solutionPath "src" "Logging.XUnit.v3" "MartinCostello.Logging.XUnit.v3.csproj")
)

$testProjects = @(
(Join-Path $solutionPath "tests" "Logging.XUnit.Tests" "MartinCostello.Logging.XUnit.Tests.csproj")
(Join-Path $solutionPath "tests" "Logging.XUnit.v3.Tests" "MartinCostello.Logging.XUnit.v3.Tests.csproj")
)

$dotnetVersion = (Get-Content $sdkFile | Out-String | ConvertFrom-Json).sdk.version
Expand Down Expand Up @@ -102,8 +106,10 @@ function DotNetTest {
}
}

Write-Information "Packaging library..."
DotNetPack $libraryProject
Write-Information "Packaging libraries..."
ForEach ($libraryProject in $libraryProjects) {
DotNetPack $libraryProject
}

if (-Not $SkipTests) {
Write-Information "Running tests..."
Expand Down
42 changes: 42 additions & 0 deletions src/Logging.XUnit.v3/MartinCostello.Logging.XUnit.v3.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<AssemblyTitle>Logging Extensions for xunit v3</AssemblyTitle>
<DefineConstants>$(DefineConstants);XUNIT_V3</DefineConstants>
<Description>Extensions for Microsoft.Extensions.Logging for xunit v3.</Description>
<EnablePackageValidation>true</EnablePackageValidation>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
<IsPackable>true</IsPackable>
<IsTestProject>false</IsTestProject>
<OutputType>Library</OutputType>
<PackageId>MartinCostello.Logging.XUnit.v3</PackageId>
<!--
<PackageValidationBaselineVersion>0.4.0</PackageValidationBaselineVersion>
-->
<RootNamespace>MartinCostello.Logging.XUnit</RootNamespace>
<Summary>$(Description)</Summary>
<TargetFrameworks>net472;net8.0</TargetFrameworks>
<TestProject>false</TestProject>
<Title>xunit v3 Logging Extensions</Title>
</PropertyGroup>
<PropertyGroup Condition="$([MSBuild]::IsTargetFrameworkCompatible('$(TargetFramework)', 'net8.0'))">
<IsAotCompatible>true</IsAotCompatible>
</PropertyGroup>
<ItemGroup>
<Compile Include="..\Shared\**\*.cs" Link="%(Link)" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Logging" VersionOverride="8.0.1" />
<PackageReference Include="xunit.v3.extensibility.core" />
</ItemGroup>
<ItemGroup>
<AssemblyAttribute Include="System.Runtime.InteropServices.GuidAttribute">
<_Parameter1>ed8d1c5e-3ee7-45fe-8d1d-94257a71f02a</_Parameter1>
</AssemblyAttribute>
<InternalsVisibleTo Include="MartinCostello.Logging.XUnit.v3.Tests" PublicKey="$(StrongNamePublicKey)" />
</ItemGroup>
<ItemGroup>
<Using Include="Xunit" />
<Using Include="Xunit.Sdk" />
<Using Include="Xunit.v3" />
</ItemGroup>
</Project>
11 changes: 0 additions & 11 deletions src/Logging.XUnit/CompatibilitySuppressions.xml

This file was deleted.

15 changes: 10 additions & 5 deletions src/Logging.XUnit/MartinCostello.Logging.XUnit.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,21 @@
<Description>Extensions for Microsoft.Extensions.Logging for xunit.</Description>
<EnablePackageValidation>true</EnablePackageValidation>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
<IsPackable>true</IsPackable>
<OutputType>Library</OutputType>
<PackageId>MartinCostello.Logging.XUnit</PackageId>
<PackageValidationBaselineVersion>0.3.0</PackageValidationBaselineVersion>
<PackageValidationBaselineVersion>0.4.0</PackageValidationBaselineVersion>
<RootNamespace>MartinCostello.Logging.XUnit</RootNamespace>
<Summary>$(Description)</Summary>
<TargetFrameworks>netstandard2.0;net8.0</TargetFrameworks>
<Title>xunit Logging Extensions</Title>
</PropertyGroup>
<PropertyGroup Condition="$([MSBuild]::IsTargetFrameworkCompatible('$(TargetFramework)', 'net8.0'))">
<EnableAotAnalyzer>true</EnableAotAnalyzer>
<EnableSingleFileAnalyzer>true</EnableSingleFileAnalyzer>
<EnableTrimAnalyzer>true</EnableTrimAnalyzer>
<IsAotCompatible>true</IsAotCompatible>
<IsTrimmable>true</IsTrimmable>
</PropertyGroup>
<ItemGroup>
<Compile Include="..\Shared\**\*.cs" Link="%(Link)" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Logging" />
<PackageReference Include="xunit.abstractions" />
Expand All @@ -33,4 +33,9 @@
</AssemblyAttribute>
<InternalsVisibleTo Include="MartinCostello.Logging.XUnit.Tests" PublicKey="$(StrongNamePublicKey)" />
</ItemGroup>
<ItemGroup>
<Using Include="Xunit" />
<Using Include="Xunit.Abstractions" />
<Using Include="Xunit.Sdk" />
</ItemGroup>
</Project>
Original file line number Diff line number Diff line change
@@ -1,27 +1,25 @@
// Copyright (c) Martin Costello, 2018. All rights reserved.
// Licensed under the Apache 2.0 license. See the LICENSE file in the project root for full license information.

using Xunit.Abstractions;

namespace MartinCostello.Logging.XUnit;

/// <summary>
/// A class representing an implementation of <see cref="ITestOutputHelperAccessor"/> that
/// stores the <see cref="ITestOutputHelper"/> as an asynchronous local value. This class cannot be inherited.
/// </summary>
internal sealed class AmbientTestOutputHelperAccessor : ITestOutputHelperAccessor
{
/// <summary>
/// A backing field for the <see cref="ITestOutputHelper"/> for the current thread.
/// </summary>
private static readonly AsyncLocal<ITestOutputHelper?> _current = new();

/// <summary>
/// Gets or sets the current <see cref="ITestOutputHelper"/>.
/// </summary>
public ITestOutputHelper? OutputHelper
{
get { return _current.Value; }
set { _current.Value = value; }
}
}
// Copyright (c) Martin Costello, 2018. All rights reserved.
// Licensed under the Apache 2.0 license. See the LICENSE file in the project root for full license information.

namespace MartinCostello.Logging.XUnit;

/// <summary>
/// A class representing an implementation of <see cref="ITestOutputHelperAccessor"/> that
/// stores the <see cref="ITestOutputHelper"/> as an asynchronous local value. This class cannot be inherited.
/// </summary>
internal sealed class AmbientTestOutputHelperAccessor : ITestOutputHelperAccessor
{
/// <summary>
/// A backing field for the <see cref="ITestOutputHelper"/> for the current thread.
/// </summary>
private static readonly AsyncLocal<ITestOutputHelper?> _current = new();

/// <summary>
/// Gets or sets the current <see cref="ITestOutputHelper"/>.
/// </summary>
public ITestOutputHelper? OutputHelper
{
get { return _current.Value; }
set { _current.Value = value; }
}
}
Original file line number Diff line number Diff line change
@@ -1,17 +1,15 @@
// Copyright (c) Martin Costello, 2018. All rights reserved.
// Licensed under the Apache 2.0 license. See the LICENSE file in the project root for full license information.

using Xunit.Abstractions;

namespace MartinCostello.Logging.XUnit;

/// <summary>
/// Defines a property for accessing an <see cref="IMessageSink"/>.
/// </summary>
public interface IMessageSinkAccessor
{
/// <summary>
/// Gets or sets the <see cref="IMessageSink"/> to use.
/// </summary>
IMessageSink? MessageSink { get; set; }
}
// Copyright (c) Martin Costello, 2018. All rights reserved.
// Licensed under the Apache 2.0 license. See the LICENSE file in the project root for full license information.

namespace MartinCostello.Logging.XUnit;

/// <summary>
/// Defines a property for accessing an <see cref="IMessageSink"/>.
/// </summary>
public interface IMessageSinkAccessor
{
/// <summary>
/// Gets or sets the <see cref="IMessageSink"/> to use.
/// </summary>
IMessageSink? MessageSink { get; set; }
}
Original file line number Diff line number Diff line change
@@ -1,53 +1,57 @@
// Copyright (c) Martin Costello, 2018. All rights reserved.
// Licensed under the Apache 2.0 license. See the LICENSE file in the project root for full license information.

using System.ComponentModel;
using Microsoft.Extensions.Logging;

#pragma warning disable IDE0130
namespace Xunit.Abstractions;

/// <summary>
/// A class containing extension methods for the <see cref="IMessageSink"/> interface. This class cannot be inherited.
/// </summary>
[EditorBrowsable(EditorBrowsableState.Never)]
public static class IMessageSinkExtensions
{
/// <summary>
/// Returns an <see cref="ILoggerFactory"/> that logs to the message sink.
/// </summary>
/// <param name="messageSink">The <see cref="IMessageSink"/> to create the logger factory from.</param>
/// <returns>
/// An <see cref="ILoggerFactory"/> that writes messages to the message sink.
/// </returns>
/// <exception cref="ArgumentNullException">
/// <paramref name="messageSink"/> is <see langword="null"/>.
/// </exception>
public static ILoggerFactory ToLoggerFactory(this IMessageSink messageSink)
{
#if NET
ArgumentNullException.ThrowIfNull(messageSink);
#else
if (messageSink == null)
{
throw new ArgumentNullException(nameof(messageSink));
}
#endif

return new LoggerFactory().AddXUnit(messageSink);
}

/// <summary>
/// Returns an <see cref="ILogger{T}"/> that logs to the message sink.
/// </summary>
/// <typeparam name="T">The type of the logger to create.</typeparam>
/// <param name="messageSink">The <see cref="IMessageSink"/> to create the logger from.</param>
/// <returns>
/// An <see cref="ILogger{T}"/> that writes messages to the message sink.
/// </returns>
/// <exception cref="ArgumentNullException">
/// <paramref name="messageSink"/> is <see langword="null"/>.
/// </exception>
public static ILogger<T> ToLogger<T>(this IMessageSink messageSink)
=> messageSink.ToLoggerFactory().CreateLogger<T>();
}
// Copyright (c) Martin Costello, 2018. All rights reserved.
// Licensed under the Apache 2.0 license. See the LICENSE file in the project root for full license information.

using System.ComponentModel;
using Microsoft.Extensions.Logging;

#if XUNIT_V3
namespace Xunit;
#else
#pragma warning disable IDE0130
namespace Xunit.Abstractions;
#endif

/// <summary>
/// A class containing extension methods for the <see cref="IMessageSink"/> interface. This class cannot be inherited.
/// </summary>
[EditorBrowsable(EditorBrowsableState.Never)]
public static class IMessageSinkExtensions
{
/// <summary>
/// Returns an <see cref="ILoggerFactory"/> that logs to the message sink.
/// </summary>
/// <param name="messageSink">The <see cref="IMessageSink"/> to create the logger factory from.</param>
/// <returns>
/// An <see cref="ILoggerFactory"/> that writes messages to the message sink.
/// </returns>
/// <exception cref="ArgumentNullException">
/// <paramref name="messageSink"/> is <see langword="null"/>.
/// </exception>
public static ILoggerFactory ToLoggerFactory(this IMessageSink messageSink)
{
#if NET
ArgumentNullException.ThrowIfNull(messageSink);
#else
if (messageSink == null)
{
throw new ArgumentNullException(nameof(messageSink));
}
#endif

return new LoggerFactory().AddXUnit(messageSink);
}

/// <summary>
/// Returns an <see cref="ILogger{T}"/> that logs to the message sink.
/// </summary>
/// <typeparam name="T">The type of the logger to create.</typeparam>
/// <param name="messageSink">The <see cref="IMessageSink"/> to create the logger from.</param>
/// <returns>
/// An <see cref="ILogger{T}"/> that writes messages to the message sink.
/// </returns>
/// <exception cref="ArgumentNullException">
/// <paramref name="messageSink"/> is <see langword="null"/>.
/// </exception>
public static ILogger<T> ToLogger<T>(this IMessageSink messageSink)
=> messageSink.ToLoggerFactory().CreateLogger<T>();
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
// Copyright (c) Martin Costello, 2018. All rights reserved.
// Licensed under the Apache 2.0 license. See the LICENSE file in the project root for full license information.

using Xunit.Abstractions;

namespace MartinCostello.Logging.XUnit;

/// <summary>
Expand Down
Loading
Loading