Skip to content

Commit 596bf94

Browse files
committed
refactor(platforms): modernize aspnetcore tfms and deps
1 parent 1129ee2 commit 596bf94

File tree

9 files changed

+74
-51
lines changed

9 files changed

+74
-51
lines changed

build/common.props

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
<PackageOutputPath>$(SolutionDir)artifacts</PackageOutputPath>
1818
<PackageIcon>exceptionless-icon.png</PackageIcon>
1919
<PackageTags>Exceptionless;Error;Error-Handling;Error-Handler;Error-Reporting;Error-Management;Error-Monitoring;Handling;Management;Monitoring;Report;Reporting;Crash-Reporting;Exception;Exception-Handling;Exception-Handler;Exception-Reporting;Exceptions;Log;Logs;Logging;Unhandled;Unhandled-Exceptions;Feature;Configuration;Debug;FeatureToggle;Metrics;ELMAH</PackageTags>
20-
<PackageLicenseExpression>APACHE-2.0</PackageLicenseExpression>
20+
<PackageLicenseExpression>Apache-2.0</PackageLicenseExpression>
2121
<RepositoryUrl>$(PackageProjectUrl)</RepositoryUrl>
2222
<PublishRepositoryUrl>true</PublishRepositoryUrl>
2323
<EmbedUntrackedSources>true</EmbedUntrackedSources>

src/Platforms/Exceptionless.AspNetCore/Exceptionless.AspNetCore.csproj

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<Import Project="..\..\..\build\common.props" />
33

44
<PropertyGroup>
5-
<TargetFrameworks>netstandard2.0</TargetFrameworks>
5+
<TargetFrameworks>net8.0;net9.0;net10.0</TargetFrameworks>
66
</PropertyGroup>
77

88
<PropertyGroup Label="Package">
@@ -22,15 +22,7 @@
2222
<ProjectReference Include="..\Exceptionless.Extensions.Hosting\Exceptionless.Extensions.Hosting.csproj" />
2323
</ItemGroup>
2424

25-
<ItemGroup Label="Package References">
26-
<PackageReference Include="Microsoft.AspNetCore.Hosting.Abstractions" Version="2.2.0" />
27-
<PackageReference Include="Microsoft.AspNetCore.Http.Abstractions" Version="2.2.0" />
28-
<PackageReference Include="Microsoft.Extensions.DiagnosticAdapter" Version="3.1.32" />
29-
<PackageReference Include="Microsoft.Net.Http.Headers" Version="2.2.8" />
30-
<PackageReference Include="System.Diagnostics.DiagnosticSource" Version="6.0.0" />
25+
<ItemGroup Label="Framework References">
26+
<FrameworkReference Include="Microsoft.AspNetCore.App" />
3127
</ItemGroup>
32-
33-
<PropertyGroup Condition=" '$(TargetFramework)' == 'netstandard2.0' " Label="Build">
34-
<DefineConstants>$(DefineConstants);NETSTANDARD2_0</DefineConstants>
35-
</PropertyGroup>
36-
</Project>
28+
</Project>
Lines changed: 40 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,49 +1,62 @@
11
using System;
2+
using System.Collections.Generic;
3+
using System.Reflection;
24
using Exceptionless.Plugins;
35
using Microsoft.AspNetCore.Http;
4-
using Microsoft.Extensions.DiagnosticAdapter;
56

67
namespace Exceptionless.AspNetCore {
7-
public sealed class ExceptionlessDiagnosticListener {
8+
public sealed class ExceptionlessDiagnosticListener : IObserver<KeyValuePair<string, object>> {
9+
private const string HandledExceptionEvent = "Microsoft.AspNetCore.Diagnostics.HandledException";
10+
private const string DiagnosticsUnhandledExceptionEvent = "Microsoft.AspNetCore.Diagnostics.UnhandledException";
11+
private const string HostingUnhandledExceptionEvent = "Microsoft.AspNetCore.Hosting.UnhandledException";
12+
private const string MiddlewareExceptionEvent = "Microsoft.AspNetCore.MiddlewareAnalysis.MiddlewareException";
813
private readonly ExceptionlessClient _client;
914

1015
public ExceptionlessDiagnosticListener(ExceptionlessClient client) {
1116
_client = client;
1217
}
1318

14-
[DiagnosticName("Microsoft.AspNetCore.Diagnostics.HandledException")]
15-
public void OnDiagnosticHandledException(HttpContext httpContext, Exception exception) {
16-
var contextData = new ContextData();
17-
contextData.SetSubmissionMethod("Microsoft.AspNetCore.Diagnostics.HandledException");
18-
19-
exception.ToExceptionless(contextData, _client).SetHttpContext(httpContext).Submit();
19+
public void OnCompleted() { }
20+
21+
public void OnError(Exception error) { }
22+
23+
public void OnNext(KeyValuePair<string, object> diagnosticEvent) {
24+
switch (diagnosticEvent.Key) {
25+
case HandledExceptionEvent:
26+
SubmitException(diagnosticEvent.Value, diagnosticEvent.Key, false);
27+
break;
28+
case DiagnosticsUnhandledExceptionEvent:
29+
case HostingUnhandledExceptionEvent:
30+
SubmitException(diagnosticEvent.Value, diagnosticEvent.Key, true);
31+
break;
32+
case MiddlewareExceptionEvent:
33+
string middlewareName = GetPropertyValue(diagnosticEvent.Value, "name") as string;
34+
SubmitException(diagnosticEvent.Value, middlewareName ?? diagnosticEvent.Key, true);
35+
break;
36+
}
2037
}
2138

22-
[DiagnosticName("Microsoft.AspNetCore.Diagnostics.UnhandledException")]
23-
public void OnDiagnosticUnhandledException(HttpContext httpContext, Exception exception) {
24-
var contextData = new ContextData();
25-
contextData.MarkAsUnhandledError();
26-
contextData.SetSubmissionMethod("Microsoft.AspNetCore.Diagnostics.UnhandledException");
39+
private void SubmitException(object payload, string submissionMethod, bool isUnhandledError) {
40+
if (payload == null)
41+
return;
2742

28-
exception.ToExceptionless(contextData, _client).SetHttpContext(httpContext).Submit();
29-
}
43+
var httpContext = GetPropertyValue(payload, "httpContext") as HttpContext;
44+
var exception = GetPropertyValue(payload, "exception") as Exception;
45+
if (httpContext == null || exception == null)
46+
return;
3047

31-
[DiagnosticName("Microsoft.AspNetCore.Hosting.UnhandledException")]
32-
public void OnHostingUnhandledException(HttpContext httpContext, Exception exception) {
3348
var contextData = new ContextData();
34-
contextData.MarkAsUnhandledError();
35-
contextData.SetSubmissionMethod("Microsoft.AspNetCore.Hosting.UnhandledException");
49+
if (isUnhandledError)
50+
contextData.MarkAsUnhandledError();
51+
contextData.SetSubmissionMethod(submissionMethod);
3652

3753
exception.ToExceptionless(contextData, _client).SetHttpContext(httpContext).Submit();
3854
}
3955

40-
[DiagnosticName("Microsoft.AspNetCore.MiddlewareAnalysis.MiddlewareException")]
41-
public void OnMiddlewareException(HttpContext httpContext, Exception exception, string name) {
42-
var contextData = new ContextData();
43-
contextData.MarkAsUnhandledError();
44-
contextData.SetSubmissionMethod(name ?? "Microsoft.AspNetCore.MiddlewareAnalysis.MiddlewareException");
45-
46-
exception.ToExceptionless(contextData, _client).SetHttpContext(httpContext).Submit();
56+
private static object GetPropertyValue(object payload, string propertyName) {
57+
return payload.GetType()
58+
.GetProperty(propertyName, BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.IgnoreCase)?
59+
.GetValue(payload);
4760
}
4861
}
49-
}
62+
}

src/Platforms/Exceptionless.AspNetCore/ExceptionlessExtensions.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ public static IApplicationBuilder UseExceptionless(this IApplicationBuilder app,
3434
//client.Configuration.Resolver.Register<ILastReferenceIdManager, WebLastReferenceIdManager>();
3535

3636
var diagnosticListener = app.ApplicationServices.GetRequiredService<DiagnosticListener>();
37-
diagnosticListener?.SubscribeWithAdapter(new ExceptionlessDiagnosticListener(client));
37+
diagnosticListener?.Subscribe(new ExceptionlessDiagnosticListener(client));
3838

3939
var lifetime = app.ApplicationServices.GetRequiredService<IHostApplicationLifetime>();
4040
lifetime.ApplicationStopping.Register(() => client.ProcessQueueAsync().ConfigureAwait(false).GetAwaiter().GetResult());

src/Platforms/Exceptionless.AspNetCore/RequestInfoCollector.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -133,8 +133,6 @@ private static object GetPostData(HttpContext context, ExceptionlessConfiguratio
133133
HeaderNames.Authorization,
134134
HeaderNames.Cookie,
135135
HeaderNames.Host,
136-
HeaderNames.Method,
137-
HeaderNames.Path,
138136
HeaderNames.ProxyAuthorization,
139137
HeaderNames.Referer,
140138
HeaderNames.UserAgent

src/Platforms/Exceptionless.Extensions.Hosting/Exceptionless.Extensions.Hosting.csproj

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,23 @@
77
<AssemblyTitle>Exceptionless provider for Microsoft.Extensions.Hosting</AssemblyTitle>
88
<Description>Exceptionless provider for Microsoft.Extensions.Hosting. $(Description)</Description>
99
<PackageTags>$(PackageTags);Microsoft.Extensions.Hosting;Hosting</PackageTags>
10-
<TargetFrameworks>netstandard2.0</TargetFrameworks>
10+
<TargetFrameworks>net8.0;net9.0;net10.0</TargetFrameworks>
1111
</PropertyGroup>
1212

1313
<ItemGroup Label="Package">
1414
<None Include="readme.txt" pack="true" PackagePath="." />
1515
</ItemGroup>
1616

17-
<ItemGroup Label="Package References">
18-
<PackageReference Include="Microsoft.Extensions.Hosting.Abstractions" Version="6.0.0" />
17+
<ItemGroup Label="Package References" Condition=" '$(TargetFramework)' == 'net8.0' ">
18+
<PackageReference Include="Microsoft.Extensions.Hosting.Abstractions" Version="8.0.1" />
19+
</ItemGroup>
20+
21+
<ItemGroup Label="Package References" Condition=" '$(TargetFramework)' == 'net9.0' ">
22+
<PackageReference Include="Microsoft.Extensions.Hosting.Abstractions" Version="9.0.14" />
23+
</ItemGroup>
24+
25+
<ItemGroup Label="Package References" Condition=" '$(TargetFramework)' == 'net10.0' ">
26+
<PackageReference Include="Microsoft.Extensions.Hosting.Abstractions" Version="10.0.5" />
1927
</ItemGroup>
2028

2129
<ItemGroup>

src/Platforms/Exceptionless.Extensions.Logging/Exceptionless.Extensions.Logging.csproj

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,23 @@
77
<AssemblyTitle>Exceptionless provider for Microsoft.Extensions.Logging</AssemblyTitle>
88
<Description>Exceptionless provider for Microsoft.Extensions.Logging. $(Description)</Description>
99
<PackageTags>$(PackageTags);Microsoft.Extensions.Logging</PackageTags>
10-
<TargetFrameworks>netstandard2.0</TargetFrameworks>
10+
<TargetFrameworks>net8.0;net9.0;net10.0</TargetFrameworks>
1111
</PropertyGroup>
1212

1313
<ItemGroup Label="Package">
1414
<None Include="readme.txt" pack="true" PackagePath="." />
1515
</ItemGroup>
1616

17-
<ItemGroup Label="Package References">
18-
<PackageReference Include="Microsoft.Extensions.Logging" Version="6.0.0" />
17+
<ItemGroup Label="Package References" Condition=" '$(TargetFramework)' == 'net8.0' ">
18+
<PackageReference Include="Microsoft.Extensions.Logging" Version="8.0.1" />
19+
</ItemGroup>
20+
21+
<ItemGroup Label="Package References" Condition=" '$(TargetFramework)' == 'net9.0' ">
22+
<PackageReference Include="Microsoft.Extensions.Logging" Version="9.0.14" />
23+
</ItemGroup>
24+
25+
<ItemGroup Label="Package References" Condition=" '$(TargetFramework)' == 'net10.0' ">
26+
<PackageReference Include="Microsoft.Extensions.Logging" Version="10.0.5" />
1927
</ItemGroup>
2028

2129
<ItemGroup>

test/Exceptionless.Tests/Exceptionless.Tests.csproj

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,14 @@
2929

3030
<ItemGroup>
3131
<ProjectReference Include="..\..\src\Exceptionless\Exceptionless.csproj" />
32-
<ProjectReference Include="..\..\src\Platforms\Exceptionless.AspNetCore\Exceptionless.AspNetCore.csproj" />
3332
<ProjectReference Include="..\Exceptionless.TestHarness\Exceptionless.TestHarness.csproj" />
3433
</ItemGroup>
3534

35+
<ItemGroup Condition=" '$(TargetFramework)' == 'net10.0' ">
36+
<ProjectReference Include="..\..\src\Platforms\Exceptionless.AspNetCore\Exceptionless.AspNetCore.csproj" />
37+
</ItemGroup>
38+
3639
<ItemGroup>
37-
<PackageReference Include="Microsoft.AspNetCore.Http" Version="2.2.0" />
3840
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.13.0" />
3941
<PackageReference Include="BenchmarkDotNet" Version="0.13.12" />
4042
<PackageReference Include="Moq" Version="4.20.72" />

test/Exceptionless.Tests/Platforms/AspNetCoreRequestInfoTests.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
#if NET10_0_OR_GREATER
12
using System.Collections.Generic;
23
using System.IO;
34
using System.Text;
@@ -82,3 +83,4 @@ private static DefaultHttpContext CreateFormHttpContext() {
8283
}
8384
}
8485
}
86+
#endif

0 commit comments

Comments
 (0)