Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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 .generated.NoMobile.slnx
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,7 @@
<Project Path="test/Sentry.Google.Cloud.Functions.Tests/Sentry.Google.Cloud.Functions.Tests.csproj" />
<Project Path="test/Sentry.Hangfire.Tests/Sentry.Hangfire.Tests.csproj" />
<Project Path="test/Sentry.Log4Net.Tests/Sentry.Log4Net.Tests.csproj" />
<Project Path="test/Sentry.Log4Net.V3.Tests/Sentry.Log4Net.V3.Tests.csproj" />
<Project Path="test/Sentry.Maui.CommunityToolkit.Mvvm.Tests/Sentry.Maui.CommunityToolkit.Mvvm.Tests.csproj" />
<Project Path="test/Sentry.Maui.Device.TestApp/Sentry.Maui.Device.TestApp.csproj" />
<Project Path="test/Sentry.Maui.Tests/Sentry.Maui.Tests.csproj" />
Expand Down
1 change: 1 addition & 0 deletions Sentry-CI-Build-Linux-NoMobile.slnf
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@
"test\\Sentry.Google.Cloud.Functions.Tests\\Sentry.Google.Cloud.Functions.Tests.csproj",
"test\\Sentry.Hangfire.Tests\\Sentry.Hangfire.Tests.csproj",
"test\\Sentry.Log4Net.Tests\\Sentry.Log4Net.Tests.csproj",
"test\\Sentry.Log4Net.V3.Tests\\Sentry.Log4Net.V3.Tests.csproj",
"test\\Sentry.NLog.Tests\\Sentry.NLog.Tests.csproj",
"test\\Sentry.OpenTelemetry.Exporter.Tests\\Sentry.OpenTelemetry.Exporter.Tests.csproj",
"test\\Sentry.OpenTelemetry.Tests\\Sentry.OpenTelemetry.Tests.csproj",
Expand Down
1 change: 1 addition & 0 deletions Sentry-CI-Build-Linux.slnf
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@
"test\\Sentry.Google.Cloud.Functions.Tests\\Sentry.Google.Cloud.Functions.Tests.csproj",
"test\\Sentry.Hangfire.Tests\\Sentry.Hangfire.Tests.csproj",
"test\\Sentry.Log4Net.Tests\\Sentry.Log4Net.Tests.csproj",
"test\\Sentry.Log4Net.V3.Tests\\Sentry.Log4Net.V3.Tests.csproj",
"test\\Sentry.Maui.CommunityToolkit.Mvvm.Tests\\Sentry.Maui.CommunityToolkit.Mvvm.Tests.csproj",
"test\\Sentry.Maui.Tests\\Sentry.Maui.Tests.csproj",
"test\\Sentry.NLog.Tests\\Sentry.NLog.Tests.csproj",
Expand Down
1 change: 1 addition & 0 deletions Sentry-CI-Build-Windows-arm64.slnf
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@
"test\\Sentry.Google.Cloud.Functions.Tests\\Sentry.Google.Cloud.Functions.Tests.csproj",
"test\\Sentry.Hangfire.Tests\\Sentry.Hangfire.Tests.csproj",
"test\\Sentry.Log4Net.Tests\\Sentry.Log4Net.Tests.csproj",
"test\\Sentry.Log4Net.V3.Tests\\Sentry.Log4Net.V3.Tests.csproj",
"test\\Sentry.Maui.CommunityToolkit.Mvvm.Tests\\Sentry.Maui.CommunityToolkit.Mvvm.Tests.csproj",
"test\\Sentry.Maui.Tests\\Sentry.Maui.Tests.csproj",
"test\\Sentry.NLog.Tests\\Sentry.NLog.Tests.csproj",
Expand Down
1 change: 1 addition & 0 deletions Sentry-CI-Build-Windows.slnf
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@
"test\\Sentry.Google.Cloud.Functions.Tests\\Sentry.Google.Cloud.Functions.Tests.csproj",
"test\\Sentry.Hangfire.Tests\\Sentry.Hangfire.Tests.csproj",
"test\\Sentry.Log4Net.Tests\\Sentry.Log4Net.Tests.csproj",
"test\\Sentry.Log4Net.V3.Tests\\Sentry.Log4Net.V3.Tests.csproj",
"test\\Sentry.Maui.CommunityToolkit.Mvvm.Tests\\Sentry.Maui.CommunityToolkit.Mvvm.Tests.csproj",
"test\\Sentry.Maui.Tests\\Sentry.Maui.Tests.csproj",
"test\\Sentry.NLog.Tests\\Sentry.NLog.Tests.csproj",
Expand Down
1 change: 1 addition & 0 deletions Sentry-CI-Build-macOS.slnf
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@
"test\\Sentry.Google.Cloud.Functions.Tests\\Sentry.Google.Cloud.Functions.Tests.csproj",
"test\\Sentry.Hangfire.Tests\\Sentry.Hangfire.Tests.csproj",
"test\\Sentry.Log4Net.Tests\\Sentry.Log4Net.Tests.csproj",
"test\\Sentry.Log4Net.V3.Tests\\Sentry.Log4Net.V3.Tests.csproj",
"test\\Sentry.Maui.CommunityToolkit.Mvvm.Tests\\Sentry.Maui.CommunityToolkit.Mvvm.Tests.csproj",
"test\\Sentry.Maui.Device.TestApp\\Sentry.Maui.Device.TestApp.csproj",
"test\\Sentry.Maui.Tests\\Sentry.Maui.Tests.csproj",
Expand Down
1 change: 1 addition & 0 deletions Sentry.slnx
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,7 @@
<Project Path="test/Sentry.Google.Cloud.Functions.Tests/Sentry.Google.Cloud.Functions.Tests.csproj" />
<Project Path="test/Sentry.Hangfire.Tests/Sentry.Hangfire.Tests.csproj" />
<Project Path="test/Sentry.Log4Net.Tests/Sentry.Log4Net.Tests.csproj" />
<Project Path="test/Sentry.Log4Net.V3.Tests/Sentry.Log4Net.V3.Tests.csproj" />
<Project Path="test/Sentry.Maui.CommunityToolkit.Mvvm.Tests/Sentry.Maui.CommunityToolkit.Mvvm.Tests.csproj" />
<Project Path="test/Sentry.Maui.Device.TestApp/Sentry.Maui.Device.TestApp.csproj" />
<Project Path="test/Sentry.Maui.Tests/Sentry.Maui.Tests.csproj" />
Expand Down
1 change: 1 addition & 0 deletions SentryNoMobile.slnf
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@
"test\\Sentry.Google.Cloud.Functions.Tests\\Sentry.Google.Cloud.Functions.Tests.csproj",
"test\\Sentry.Hangfire.Tests\\Sentry.Hangfire.Tests.csproj",
"test\\Sentry.Log4Net.Tests\\Sentry.Log4Net.Tests.csproj",
"test\\Sentry.Log4Net.V3.Tests\\Sentry.Log4Net.V3.Tests.csproj",
"test\\Sentry.NLog.Tests\\Sentry.NLog.Tests.csproj",
"test\\Sentry.OpenTelemetry.Exporter.Tests\\Sentry.OpenTelemetry.Exporter.Tests.csproj",
"test\\Sentry.OpenTelemetry.Tests\\Sentry.OpenTelemetry.Tests.csproj",
Expand Down
1 change: 1 addition & 0 deletions SentryNoSamples.slnf
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
"test\\Sentry.Google.Cloud.Functions.Tests\\Sentry.Google.Cloud.Functions.Tests.csproj",
"test\\Sentry.Hangfire.Tests\\Sentry.Hangfire.Tests.csproj",
"test\\Sentry.Log4Net.Tests\\Sentry.Log4Net.Tests.csproj",
"test\\Sentry.Log4Net.V3.Tests\\Sentry.Log4Net.V3.Tests.csproj",
"test\\Sentry.Maui.CommunityToolkit.Mvvm.Tests\\Sentry.Maui.CommunityToolkit.Mvvm.Tests.csproj",
"test\\Sentry.Maui.Tests\\Sentry.Maui.Tests.csproj",
"test\\Sentry.NLog.Tests\\Sentry.NLog.Tests.csproj",
Expand Down
1 change: 1 addition & 0 deletions src/Sentry.Log4Net/Sentry.Log4Net.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@

<ItemGroup>
<InternalsVisibleTo Include="Sentry.Log4Net.Tests" PublicKey="$(SentryPublicKey)" />
<InternalsVisibleTo Include="Sentry.Log4Net.V3.Tests" PublicKey="$(SentryPublicKey)" />
</ItemGroup>

<ItemGroup>
Expand Down
18 changes: 12 additions & 6 deletions src/Sentry.Log4Net/SentryAppender.Structured.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,20 @@ private static void CaptureStructuredLog(IHub hub, SentryOptions options, Loggin
// against null, so we do too rather than rely on log4net's internals.
if (loggingEvent.GetProperties() is { } properties)
{
foreach (var property in properties)
// Read through GetKeys()/the indexer rather than enumerating the dictionary. log4net 3.x added
// IDictionary<string, object?> to PropertiesDictionary, which changed what its non-generic
// IEnumerable yields (KeyValuePair<string, object?> instead of DictionaryEntry), so enumerating
// silently matched nothing there. GetKeys() behaves the same on both majors.
foreach (var key in properties.GetKeys())
{
if (property is DictionaryEntry { Key: string key, Value: { } value })
if (string.IsNullOrEmpty(key) || key.StartsWith("log4net:", StringComparison.OrdinalIgnoreCase) || Guid.TryParse(key, out _))
{
if (key.Length != 0 && !key.StartsWith("log4net:", StringComparison.OrdinalIgnoreCase) && !Guid.TryParse(key, out _))
{
log.SetAttribute($"property.{key}", value);
}
continue;
}

if (properties[key] is { } value)
Comment thread
jamescrosswell marked this conversation as resolved.
{
log.SetAttribute($"property.{key}", value);
}
}
}
Expand Down
1 change: 1 addition & 0 deletions src/Sentry/Sentry.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,7 @@
<InternalsVisibleTo Include="Sentry.Hangfire.Tests" PublicKey="$(SentryPublicKey)" />
<InternalsVisibleTo Include="Sentry.Log4Net" PublicKey="$(SentryPublicKey)" />
<InternalsVisibleTo Include="Sentry.Log4Net.Tests" PublicKey="$(SentryPublicKey)" />
<InternalsVisibleTo Include="Sentry.Log4Net.V3.Tests" PublicKey="$(SentryPublicKey)" />
<InternalsVisibleTo Include="Sentry.Maui" PublicKey="$(SentryPublicKey)" />
<InternalsVisibleTo Include="Sentry.Maui.CommunityToolkit.Mvvm" PublicKey="$(SentryPublicKey)" />
<InternalsVisibleTo Include="Sentry.Maui.CommunityToolkit.Mvvm.Tests" PublicKey="$(SentryPublicKey)" />
Expand Down
41 changes: 41 additions & 0 deletions test/Sentry.Log4Net.V3.Tests/Sentry.Log4Net.V3.Tests.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>$(LatestTfm)</TargetFrameworks>
<!-- These tests fail on Mono -->
<TargetFrameworks Condition="$([MSBuild]::IsOSPlatform('Windows'))">$(TargetFrameworks);net48</TargetFrameworks>
</PropertyGroup>

<!--
The appender tests from Sentry.Log4Net.Tests, run against log4net 3.x instead of 2.x.

Sentry.Log4Net keeps its 2.0.12 floor, so this covers what users on log4net 3.x actually get: the
2.x-compiled appender loaded against the 3.x assembly. log4net 3.x added IDictionary<string, object?>
to PropertiesDictionary, which changes what its non-generic IEnumerable yields - a runtime-only
difference that no amount of building against 2.x can catch. See #5557.

Source is linked rather than duplicated so the two majors can never drift apart. The Verify-based
tests are deliberately not linked: their snapshots are keyed off the original file paths, and running
them from two projects would have both writing the same files.
-->
Comment thread
jamescrosswell marked this conversation as resolved.
Outdated
<ItemGroup>
<Compile Include="..\Sentry.Log4Net.Tests\SentryAppenderTests.cs" Link="SentryAppenderTests.cs" />
<Compile Include="..\Sentry.Log4Net.Tests\SentryAppenderTests.Structured.cs" Link="SentryAppenderTests.Structured.cs">
<DependentUpon>SentryAppenderTests.cs</DependentUpon>
</Compile>
</ItemGroup>

<ItemGroup>
<PackageReference Include="log4net" Version="3.4.0" />
<ProjectReference Include="..\..\src\Sentry.Log4Net\Sentry.Log4Net.csproj" />
<ProjectReference Include="..\Sentry.Testing\Sentry.Testing.csproj" />

<Using Include="log4net" />
<Using Include="log4net.Core" />
<Using Include="log4net.Appender" />
<Using Include="log4net.Layout" />
<Using Include="log4net.Repository.Hierarchy" />
<Using Include="Sentry.Log4Net" />
</ItemGroup>

</Project>
1 change: 1 addition & 0 deletions test/Sentry.Testing/Sentry.Testing.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
<InternalsVisibleTo Include="Sentry.Google.Cloud.Functions.Tests" PublicKey="$(SentryPublicKey)" />
<InternalsVisibleTo Include="Sentry.GraphQL.Client.Tests" PublicKey="$(SentryPublicKey)" />
<InternalsVisibleTo Include="Sentry.Log4Net.Tests" PublicKey="$(SentryPublicKey)" />
<InternalsVisibleTo Include="Sentry.Log4Net.V3.Tests" PublicKey="$(SentryPublicKey)" />
<InternalsVisibleTo Include="Sentry.Maui.Tests" PublicKey="$(SentryPublicKey)" />
<InternalsVisibleTo Include="Sentry.NLog.Tests" PublicKey="$(SentryPublicKey)" />
<InternalsVisibleTo Include="Sentry.Profiling.Tests" PublicKey="$(SentryPublicKey)" />
Expand Down
Loading