Skip to content
Merged
Show file tree
Hide file tree
Changes from 14 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
2 changes: 1 addition & 1 deletion .vsconfig
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"components": [
"Microsoft.VisualStudio.Component.CoreEditor",
"Microsoft.VisualStudio.Workload.CoreEditor",
"Microsoft.NetCore.Component.Runtime.9.0",
"Microsoft.NetCore.Component.Runtime.10.0",
"Microsoft.NetCore.Component.SDK",
"Microsoft.VisualStudio.Component.Roslyn.Compiler",
"Microsoft.VisualStudio.Component.Roslyn.LanguageServices"
Expand Down
6 changes: 4 additions & 2 deletions Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,15 @@
<AssemblyIsCLSCompliant>false</AssemblyIsCLSCompliant>
<CodeAnalysisRuleSet>$(MSBuildThisFileDirectory)Logging.XUnit.ruleset</CodeAnalysisRuleSet>
<ManagePackageVersionsCentrally>true</ManagePackageVersionsCentrally>
<!-- TODO Remove when .NET 10 is stable -->
<NoWarn>$(NoWarn);NU5104</NoWarn>
<NuGetAuditMode>direct</NuGetAuditMode>
<PackageTags>xunit;logging</PackageTags>
<UseArtifactsOutput>true</UseArtifactsOutput>
<UseDefaultAssemblyOriginatorKeyFile>true</UseDefaultAssemblyOriginatorKeyFile>
<AssemblyVersion>0.6.0.0</AssemblyVersion>
<AssemblyVersion>0.7.0.0</AssemblyVersion>
<PackageValidationBaselineVersion>0.6.0</PackageValidationBaselineVersion>
<VersionPrefix>0.6.1</VersionPrefix>
<VersionPrefix>0.7.0</VersionPrefix>
</PropertyGroup>
<PropertyGroup Condition=" '$(EnableReferenceTrimmer)' != 'false' and '$(GenerateDocumentationFile)' != 'true' ">
<GenerateDocumentationFile>true</GenerateDocumentationFile>
Expand Down
4 changes: 2 additions & 2 deletions Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@
<PackageVersion Include="coverlet.msbuild" Version="6.0.4" />
<PackageVersion Include="GitHubActionsTestLogger" Version="2.4.1" />
<PackageVersion Include="JunitXml.TestLogger" Version="7.0.2" />
<PackageVersion Include="Microsoft.AspNetCore.Mvc.Testing" Version="9.0.10" />
<PackageVersion Include="Microsoft.AspNetCore.Mvc.Testing" Version="10.0.0" />
<PackageVersion Include="Microsoft.CodeAnalysis.PublicApiAnalyzers" Version="4.14.0" />
<PackageVersion Include="Microsoft.Extensions.Logging" Version="9.0.10" />
<PackageVersion Include="Microsoft.Extensions.Logging" Version="10.0.0" />
<PackageVersion Include="Microsoft.NET.Test.Sdk" Version="18.0.1" />
<PackageVersion Include="NSubstitute" Version="5.3.0" />
<PackageVersion Include="ReportGenerator" Version="5.4.18" />
Expand Down
2 changes: 1 addition & 1 deletion global.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"sdk": {
"version": "9.0.306",
"version": "10.0.100",
"allowPrerelease": false,
"rollForward": "latestMajor",
"paths": [ ".dotnet", "$host$" ],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<OutputType>Library</OutputType>
<PackageId>MartinCostello.Logging.XUnit.v3</PackageId>
<RootNamespace>MartinCostello.Logging.XUnit</RootNamespace>
<TargetFrameworks>net8.0;net472</TargetFrameworks>
<TargetFrameworks>net10.0;net8.0;net472</TargetFrameworks>
<Title>xunit v3 Logging Extensions</Title>
</PropertyGroup>
<ItemGroup>
Expand All @@ -19,6 +19,9 @@
<PackageReference Include="Microsoft.Extensions.Logging" VersionOverride="[8.0.1,)" />
<PackageReference Include="xunit.v3.extensibility.core" VersionOverride="[2.0.1,)" />
</ItemGroup>
<ItemGroup Condition="$([MSBuild]::IsTargetFrameworkCompatible('$(TargetFramework)', 'net10.0'))">
<PackageReference Update="Microsoft.Extensions.Logging" VersionOverride="[10.0.0,)" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.CodeAnalysis.PublicApiAnalyzers" PrivateAssets="All" />
</ItemGroup>
Expand Down
5 changes: 4 additions & 1 deletion src/Logging.XUnit/MartinCostello.Logging.XUnit.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<OutputType>Library</OutputType>
<PackageId>MartinCostello.Logging.XUnit</PackageId>
<RootNamespace>MartinCostello.Logging.XUnit</RootNamespace>
<TargetFrameworks>netstandard2.0;net8.0</TargetFrameworks>
<TargetFrameworks>net10.0;net8.0;netstandard2.0</TargetFrameworks>
<Title>xunit Logging Extensions</Title>
</PropertyGroup>
<ItemGroup>
Expand All @@ -19,6 +19,9 @@
<PackageReference Include="xunit.abstractions" VersionOverride="[2.0.3,)" />
<PackageReference Include="xunit.extensibility.execution" VersionOverride="[2.6.6,)" />
</ItemGroup>
<ItemGroup Condition="$([MSBuild]::IsTargetFrameworkCompatible('$(TargetFramework)', 'net10.0'))">
<PackageReference Update="Microsoft.Extensions.Logging" VersionOverride="[10.0.0,)" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.CodeAnalysis.PublicApiAnalyzers" PrivateAssets="All" />
</ItemGroup>
Expand Down
29 changes: 29 additions & 0 deletions src/Shared/ArgumentNullExceptionExtensions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// 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.

#if NETFRAMEWORK || NETSTANDARD
using System.Runtime.CompilerServices;

#pragma warning disable IDE0130
namespace System;

/// <summary>
/// Extension methods for <see cref="ArgumentNullException"/>.
/// </summary>
internal static class ArgumentNullExceptionExtensions
{
extension(ArgumentNullException)
{
/// <summary>Throws an <see cref="ArgumentNullException"/> if <paramref name="argument"/> is null.</summary>
/// <param name="argument">The reference type argument to validate as non-null.</param>
/// <param name="paramName">The name of the parameter with which <paramref name="argument"/> corresponds.</param>
public static void ThrowIfNull(object? argument, [CallerArgumentExpression(nameof(argument))] string? paramName = null)
{
if (argument is null)
{
throw new ArgumentNullException(paramName);
}
}
}
}
#endif
20 changes: 20 additions & 0 deletions src/Shared/CallerArgumentExpressionAttribute.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// 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.

#if NETFRAMEWORK || NETSTANDARD
#pragma warning disable IDE0130
namespace System.Runtime.CompilerServices;

/// <summary>
/// Indicates that a parameter captures the expression passed for another parameter as a string.
/// </summary>
/// <param name="parameterName">The name of the parameter whose expression should be captured as a string.</param>
[AttributeUsage(AttributeTargets.Parameter, AllowMultiple = false, Inherited = false)]
internal sealed class CallerArgumentExpressionAttribute(string parameterName) : Attribute
{
/// <summary>
/// Gets the name of the parameter whose expression should be captured as a string.
/// </summary>
public string ParameterName { get; } = parameterName;
}
#endif
7 changes: 0 additions & 7 deletions src/Shared/IMessageSinkExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,7 @@ public static class IMessageSinkExtensions
/// </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);
}
Expand Down
7 changes: 0 additions & 7 deletions src/Shared/ITestOutputHelperExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,7 @@ public static class ITestOutputHelperExtensions
/// </exception>
public static ILoggerFactory ToLoggerFactory(this ITestOutputHelper outputHelper)
{
#if NET
ArgumentNullException.ThrowIfNull(outputHelper);
#else
if (outputHelper == null)
{
throw new ArgumentNullException(nameof(outputHelper));
}
#endif

return new LoggerFactory().AddXUnit(outputHelper);
}
Expand Down
2 changes: 1 addition & 1 deletion src/Shared/StringSyntaxAttribute.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

//// Based on https://github.com/dotnet/runtime/blob/65067052e433eda400c5e7cc9f7b21c84640f901/src/libraries/System.Private.CoreLib/src/System/Diagnostics/CodeAnalysis/StringSyntaxAttribute.cs

#if NETSTANDARD || !NETCOREAPP
#if NETFRAMEWORK || NETSTANDARD

#pragma warning disable IDE0130
#pragma warning disable SA1600
Expand Down
14 changes: 0 additions & 14 deletions src/Shared/XUnitLogger.cs
Original file line number Diff line number Diff line change
Expand Up @@ -105,14 +105,7 @@ private XUnitLogger(string name, XUnitLoggerOptions? options)
public IDisposable? BeginScope<TState>(TState state)
where TState : notnull
{
#if NET
ArgumentNullException.ThrowIfNull(state);
#else
if (state == null)
{
throw new ArgumentNullException(nameof(state));
}
#endif

return XUnitLogScope.Push(state);
}
Expand All @@ -136,14 +129,7 @@ public void Log<TState>(LogLevel logLevel, EventId eventId, TState state, Except
return;
}

#if NET
ArgumentNullException.ThrowIfNull(formatter);
#else
if (formatter == null)
{
throw new ArgumentNullException(nameof(formatter));
}
#endif

string? message = formatter(state, exception);

Expand Down
Loading
Loading