-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
75 additions
and
1 deletion.
There are no files selected for viewing
33 changes: 33 additions & 0 deletions
33
src/Serilog.Enrichers.ClassName.Tests/ClassNameEnricherTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
using Serilog.Sinks.TestCorrelator; | ||
|
||
namespace Serilog.Enrichers.ClassName.Tests | ||
{ | ||
public class ClassNameEnricherTests | ||
{ | ||
[Fact] | ||
public void ClassNameProperty_MustExistAndMatch() | ||
{ | ||
// Arrange | ||
const string expectedClassName = "ClassNameEnricher"; | ||
var logger = new LoggerConfiguration() | ||
.Enrich.With(new ClassNameEnricher()) | ||
.WriteTo.TestCorrelator() | ||
.CreateLogger() | ||
.ForContext("SourceContext", typeof(ClassNameEnricher).FullName); | ||
|
||
using (TestCorrelator.CreateContext()) | ||
{ | ||
// Act | ||
logger.Information("Test log"); | ||
|
||
// Assert | ||
var logEvent = TestCorrelator.GetLogEventsFromCurrentContext().Single(); | ||
Assert.NotNull(logEvent); | ||
|
||
// Verify if the UserId property is added | ||
Assert.True(logEvent.Properties.ContainsKey("ClassName")); | ||
Assert.Equal(expectedClassName, logEvent.Properties["ClassName"].ToString().Trim('"')); | ||
} | ||
} | ||
} | ||
} |
35 changes: 35 additions & 0 deletions
35
src/Serilog.Enrichers.ClassName.Tests/Serilog.Enrichers.ClassName.Tests.csproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>net8.0</TargetFramework> | ||
<ImplicitUsings>enable</ImplicitUsings> | ||
<Nullable>enable</Nullable> | ||
|
||
<IsPackable>false</IsPackable> | ||
<IsTestProject>true</IsTestProject> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="coverlet.collector" Version="6.0.2"> | ||
<PrivateAssets>all</PrivateAssets> | ||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets> | ||
</PackageReference> | ||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.11.1" /> | ||
<PackageReference Include="Serilog" Version="3.1.1" /> | ||
<PackageReference Include="Serilog.Sinks.TestCorrelator" Version="4.0.0" /> | ||
<PackageReference Include="xunit" Version="2.9.2" /> | ||
<PackageReference Include="xunit.runner.visualstudio" Version="2.8.2"> | ||
<PrivateAssets>all</PrivateAssets> | ||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets> | ||
</PackageReference> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\Serilog.Enrichers.ClassName\Serilog.Enrichers.ClassName.csproj" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<Using Include="Xunit" /> | ||
</ItemGroup> | ||
|
||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters