Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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 .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ indent_style = space
trim_trailing_whitespace = true
charset = utf-8
end_of_line = lf
max_line_length = 120

# Verify settings
# https://github.com/VerifyTests/Verify?tab=readme-ov-file#text-file-settings
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/cicd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ jobs:
all:
if: github.run_id != 1
name: Build & Tests
uses: dailydevops/pipelines/.github/workflows/cicd-dotnet.yml@0.14.68
uses: dailydevops/pipelines/.github/workflows/cicd-dotnet.yml@0.14.82
with:
enableSonarQube: true
dotnet-logging: ${{ inputs.dotnet-logging }}
Expand Down
6 changes: 0 additions & 6 deletions Directory.Build.props
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
<Project>

<PropertyGroup Label="Package settings">
<Title>$(MSBuildProjectName)</Title>
<Description>Extensions for `ILogger` implementations to log messages to xUnit test output.</Description>
Expand All @@ -8,20 +7,15 @@
<PackageReleaseNotes>$(RepositoryUrl)/releases/tag/$(Version)</PackageReleaseNotes>
<PackageTags>logging;provider;xunit</PackageTags>
<CopyrightYearStart>2024</CopyrightYearStart>

<SuppressTfmSupportBuildWarnings>true</SuppressTfmSupportBuildWarnings>
</PropertyGroup>

<PropertyGroup>
<ProjectTargetFrameworks>net6.0;net7.0;net8.0;net9.0</ProjectTargetFrameworks>
<TestTargetFrameworks>net6.0;net7.0;net8.0;net9.0</TestTargetFrameworks>

<DisableBannedApiForUTC>true</DisableBannedApiForUTC>
</PropertyGroup>

<PropertyGroup>
<!-- Workaround, until https://github.com/GitTools/GitVersion/pull/4206 is released -->
<GitVersionTargetFramework>net8.0</GitVersionTargetFramework>
</PropertyGroup>

</Project>
10 changes: 7 additions & 3 deletions Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,18 @@
<CentralPackageTransitivePinningEnabled>true</CentralPackageTransitivePinningEnabled>
</PropertyGroup>
<ItemGroup>
<GlobalPackageReference Include="CSharpier.MSBuild" Version="0.30.6" />
<GlobalPackageReference Include="CSharpier.MSBuild" Version="1.0.1" />
<GlobalPackageReference Include="GitVersion.MsBuild" Version="6.1.0" />
<GlobalPackageReference Include="Microsoft.CodeAnalysis.BannedApiAnalyzers" Version="3.3.4" />
<GlobalPackageReference Include="Microsoft.CodeAnalysis.NetAnalyzers" Version="9.0.0" />
<GlobalPackageReference Include="Microsoft.SourceLink.GitHub" Version="8.0.0" />
<GlobalPackageReference Include="Microsoft.VisualStudio.Threading.Analyzers" Version="17.13.61" />
<GlobalPackageReference Include="NetEvolve.Defaults" Version="1.3.74" />
<GlobalPackageReference Include="SonarAnalyzer.CSharp" Version="10.6.0.109712" Condition=" '$(BuildingInsideVisualStudio)' == 'true' " />
<GlobalPackageReference Include="NetEvolve.Defaults" Version="1.3.80" />
<GlobalPackageReference
Include="SonarAnalyzer.CSharp"
Version="10.6.0.109712"
Condition=" '$(BuildingInsideVisualStudio)' == 'true' "
/>
</ItemGroup>
<ItemGroup>
<PackageVersion Include="coverlet.collector" Version="6.0.4" />
Expand Down
2 changes: 0 additions & 2 deletions nuget.config
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,13 @@
<config>
<!--<add key="defaultPushSource" value="https://contoso.com/packages/" />-->
</config>

<!-- Define the package sources, nuget.org and contoso.com. -->
<!-- `clear` ensures no additional sources are inherited from another config file. -->
<packageSources>
<clear />
<!-- `key` can be any identifier for your source. -->
<add key="nuget.org" value="https://api.nuget.org/v3/index.json" />
</packageSources>

<!-- Define mappings by adding package patterns beneath the target source. -->
<!-- Contoso.* packages and NuGet.Common will be restored from contoso.com, everything else from nuget.org. -->
<packageSourceMapping>
Expand Down
8 changes: 4 additions & 4 deletions src/NetEvolve.Logging.XUnit/NetEvolve.Logging.XUnit.csproj
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>$(ProjectTargetFrameworks)</TargetFrameworks>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.Bcl.TimeProvider" Condition=" !$([MSBuild]::IsTargetFrameworkCompatible('$(TargetFramework)', 'net8.0')) " />
<PackageReference
Include="Microsoft.Bcl.TimeProvider"
Condition=" !$([MSBuild]::IsTargetFrameworkCompatible('$(TargetFramework)', 'net8.0')) "
/>
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" />
<PackageReference Include="Microsoft.Extensions.Logging.Configuration" />
<PackageReference Include="NetEvolve.Arguments" />
<PackageReference Include="NetEvolve.Logging.Abstractions" />
<PackageReference Include="xunit.extensibility.core" />
<PackageReference Include="xunit.extensibility.execution" />
</ItemGroup>

</Project>
27 changes: 7 additions & 20 deletions src/NetEvolve.Logging.XUnit/XUnitLogger.cs
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,7 @@ public static XUnitLogger<T> CreateLogger<T>(
IExternalScopeProvider? scopeProvider = null,
IXUnitLoggerOptions? options = null
)
where T : notnull =>
CreateLogger<T>(messageSink, TimeProvider.System, scopeProvider, options);
where T : notnull => CreateLogger<T>(messageSink, TimeProvider.System, scopeProvider, options);

/// <summary>
/// Creates a new instance of <see cref="XUnitLogger{T}"/>.
Expand Down Expand Up @@ -159,8 +158,7 @@ public static XUnitLogger<T> CreateLogger<T>(
IExternalScopeProvider? scopeProvider = null,
IXUnitLoggerOptions? options = null
)
where T : notnull =>
CreateLogger<T>(testOutputHelper, TimeProvider.System, scopeProvider, options);
where T : notnull => CreateLogger<T>(testOutputHelper, TimeProvider.System, scopeProvider, options);

/// <summary>
/// Creates a new instance of <see cref="XUnitLogger{T}"/>.
Expand Down Expand Up @@ -233,9 +231,7 @@ public void Log<TState>(
var now = _timeProvider.GetLocalNow();
var (fullMessage, scopes) = CreateMessage(logLevel, state, exception, message, now);

_loggedMessages.Add(
new LoggedMessage(now, logLevel, eventId, message, exception, scopes)
);
_loggedMessages.Add(new LoggedMessage(now, logLevel, eventId, message, exception, scopes));

_writeToLog.Invoke(fullMessage);
}
Expand Down Expand Up @@ -263,9 +259,7 @@ DateTimeOffset now
{
if (!_options.DisableTimestamp)
{
_ = builder
.Append(now.ToString(_options.TimestampFormat, CultureInfo.InvariantCulture))
.Append(' ');
_ = builder.Append(now.ToString(_options.TimestampFormat, CultureInfo.InvariantCulture)).Append(' ');
}

if (!_options.DisableLogLevel)
Expand Down Expand Up @@ -341,10 +335,8 @@ private static void PrintScope(object? scope, StringBuilder state)
: state.Append(scope);
}

private static void AddAdditionalInformation(
StringBuilder builder,
KeyValuePair<string, object?> info
) => _ = builder.Append('\n').Append(' ', 4).Append(info.Key).Append(": ").Append(info.Value);
private static void AddAdditionalInformation(StringBuilder builder, KeyValuePair<string, object?> info) =>
_ = builder.Append('\n').Append(' ', 4).Append(info.Key).Append(": ").Append(info.Value);

#pragma warning disable IDE0072 // Add missing cases
internal static string LogLevelToString(LogLevel logLevel) =>
Expand Down Expand Up @@ -382,12 +374,7 @@ public override string ToString()
if (!_options.DisableTimestamp)
{
_ = builder
.Append(
lmsg.Timestamp.ToString(
_options.TimestampFormat,
CultureInfo.InvariantCulture
)
)
.Append(lmsg.Timestamp.ToString(_options.TimestampFormat, CultureInfo.InvariantCulture))
.Append(' ');
}

Expand Down
28 changes: 12 additions & 16 deletions src/NetEvolve.Logging.XUnit/XUnitLoggerExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,12 @@ public static ILoggingBuilder AddXUnit(
services.TryAddSingleton(_ => TimeProvider.System);
services.TryAddScoped<IExternalScopeProvider, LoggerExternalScopeProvider>();
services.TryAddEnumerable(
ServiceDescriptor.Singleton<ILoggerProvider, XUnitLoggerProvider>(
sp => new XUnitLoggerProvider(
sp.GetRequiredService<ITestOutputHelper>(),
sp.GetRequiredService<TimeProvider>(),
sp.GetRequiredService<IExternalScopeProvider>(),
options ?? XUnitLoggerOptions.Default
)
)
ServiceDescriptor.Singleton<ILoggerProvider, XUnitLoggerProvider>(sp => new XUnitLoggerProvider(
sp.GetRequiredService<ITestOutputHelper>(),
sp.GetRequiredService<TimeProvider>(),
sp.GetRequiredService<IExternalScopeProvider>(),
options ?? XUnitLoggerOptions.Default
))
);

return builder;
Expand All @@ -56,14 +54,12 @@ public static ILoggingBuilder AddXUnit(
services.TryAddSingleton(_ => TimeProvider.System);
services.TryAddScoped<IExternalScopeProvider, LoggerExternalScopeProvider>();
services.TryAddEnumerable(
ServiceDescriptor.Singleton<ILoggerProvider, XUnitLoggerProvider>(
sp => new XUnitLoggerProvider(
sp.GetRequiredService<IMessageSink>(),
sp.GetRequiredService<TimeProvider>(),
sp.GetRequiredService<IExternalScopeProvider>(),
options ?? XUnitLoggerOptions.Default
)
)
ServiceDescriptor.Singleton<ILoggerProvider, XUnitLoggerProvider>(sp => new XUnitLoggerProvider(
sp.GetRequiredService<IMessageSink>(),
sp.GetRequiredService<TimeProvider>(),
sp.GetRequiredService<IExternalScopeProvider>(),
options ?? XUnitLoggerOptions.Default
))
);

return builder;
Expand Down
4 changes: 1 addition & 3 deletions src/NetEvolve.Logging.XUnit/XUnitLoggerOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,7 @@ public class XUnitLoggerOptions : IXUnitLoggerOptions

/// <inheritdoc cref="IXUnitLoggerOptions.TimestampFormat"/>
#if NET7_0_OR_GREATER
[System.Diagnostics.CodeAnalysis.StringSyntax(
System.Diagnostics.CodeAnalysis.StringSyntaxAttribute.DateTimeFormat
)]
[System.Diagnostics.CodeAnalysis.StringSyntax(System.Diagnostics.CodeAnalysis.StringSyntaxAttribute.DateTimeFormat)]
#endif
public string TimestampFormat
{
Expand Down
5 changes: 1 addition & 4 deletions src/NetEvolve.Logging.XUnit/XUnitLoggerProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,7 @@
using Xunit.Sdk;

[ProviderAlias("XUnit")]
internal sealed class XUnitLoggerProvider
: ILoggerProvider,
ISupportExternalScope,
IXUnitLoggerOptions
internal sealed class XUnitLoggerProvider : ILoggerProvider, ISupportExternalScope, IXUnitLoggerOptions
{
private readonly Action<string?> _writeToAction;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>$(TestTargetFrameworks)</TargetFrameworks>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="coverlet.collector">
<PrivateAssets>all</PrivateAssets>
Expand All @@ -22,9 +20,7 @@
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\..\src\NetEvolve.Logging.XUnit\NetEvolve.Logging.XUnit.csproj" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@ public partial class XUnitLoggerExtensionsTests
{
private readonly ITestOutputHelper _testOutputHelper;

public XUnitLoggerExtensionsTests(ITestOutputHelper testOutputHelper) =>
_testOutputHelper = testOutputHelper;
public XUnitLoggerExtensionsTests(ITestOutputHelper testOutputHelper) => _testOutputHelper = testOutputHelper;

[Theory]
[MemberData(nameof(AddXUnitData))]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@ public partial class XUnitLoggerTests
);
private readonly ITestOutputHelper _testOutputHelper;

public XUnitLoggerTests(ITestOutputHelper testOutputHelper) =>
_testOutputHelper = testOutputHelper;
public XUnitLoggerTests(ITestOutputHelper testOutputHelper) => _testOutputHelper = testOutputHelper;

[Fact]
public void LoggedMessages_Empty_Expected()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,7 @@ bool disableTimestamp
_ = await Verifier
.Verify(logger.LoggedMessages)
.HashParameters()
.UseParameters(
disableAdditionalInformation,
disableLogLevel,
disableScopes,
disableTimestamp
);
.UseParameters(disableAdditionalInformation, disableLogLevel, disableScopes, disableTimestamp);
}

[Theory]
Expand Down Expand Up @@ -96,12 +91,7 @@ bool disableTimestamp
_ = await Verifier
.Verify(logger.ToString())
.HashParameters()
.UseParameters(
disableAdditionalInformation,
disableLogLevel,
disableScopes,
disableTimestamp
);
.UseParameters(disableAdditionalInformation, disableLogLevel, disableScopes, disableTimestamp);
}

[Theory]
Expand Down Expand Up @@ -139,12 +129,7 @@ bool disableTimestamp
_ = await Verifier
.Verify(logger.LoggedMessages)
.HashParameters()
.UseParameters(
disableAdditionalInformation,
disableLogLevel,
disableScopes,
disableTimestamp
);
.UseParameters(disableAdditionalInformation, disableLogLevel, disableScopes, disableTimestamp);
}

[Theory]
Expand Down Expand Up @@ -182,12 +167,7 @@ bool disableTimestamp
_ = await Verifier
.Verify(logger.ToString())
.HashParameters()
.UseParameters(
disableAdditionalInformation,
disableLogLevel,
disableScopes,
disableTimestamp
);
.UseParameters(disableAdditionalInformation, disableLogLevel, disableScopes, disableTimestamp);
}

[Theory]
Expand Down Expand Up @@ -225,12 +205,7 @@ bool disableTimestamp
_ = await Verifier
.Verify(logger.LoggedMessages)
.HashParameters()
.UseParameters(
disableAdditionalInformation,
disableLogLevel,
disableScopes,
disableTimestamp
);
.UseParameters(disableAdditionalInformation, disableLogLevel, disableScopes, disableTimestamp);
}

[Theory]
Expand Down Expand Up @@ -268,12 +243,7 @@ bool disableTimestamp
_ = await Verifier
.Verify(logger.ToString())
.HashParameters()
.UseParameters(
disableAdditionalInformation,
disableLogLevel,
disableScopes,
disableTimestamp
);
.UseParameters(disableAdditionalInformation, disableLogLevel, disableScopes, disableTimestamp);
}

public static TheoryData<bool, bool, bool, bool> LoggedMessageOrToStringData =>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>$(TestTargetFrameworks)</TargetFrameworks>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="coverlet.collector">
<PrivateAssets>all</PrivateAssets>
Expand All @@ -21,9 +19,7 @@
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\..\src\NetEvolve.Logging.XUnit\NetEvolve.Logging.XUnit.csproj" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@ public class XUnitLoggerExtensionsTests
{
private readonly ITestOutputHelper _testOutputHelper;

public XUnitLoggerExtensionsTests(ITestOutputHelper testOutputHelper) =>
_testOutputHelper = testOutputHelper;
public XUnitLoggerExtensionsTests(ITestOutputHelper testOutputHelper) => _testOutputHelper = testOutputHelper;

[Fact]
public void AddXUnit_WithNullBuilder_ThrowArgumentNullException()
Expand Down
Loading