diff --git a/dotnet-logging/Exceptionless/ExceptionlessTestClient/Controllers/ValuesController.cs b/dotnet-logging/Exceptionless/ExceptionlessTestClient/Controllers/ValuesController.cs index 240520a1ba..0faa2bc918 100644 --- a/dotnet-logging/Exceptionless/ExceptionlessTestClient/Controllers/ValuesController.cs +++ b/dotnet-logging/Exceptionless/ExceptionlessTestClient/Controllers/ValuesController.cs @@ -1,7 +1,7 @@ using Exceptionless; using Microsoft.AspNetCore.Mvc; -namespace ExceptionlessClient.Controllers; +namespace ExceptionlessDemo.Controllers; [Route("api/[controller]")] [ApiController] @@ -31,14 +31,14 @@ public void ManualException() [Route("logs")] public void Logs() { - Exceptionless.ExceptionlessClient.Default.SubmitLog("Logging a message."); + ExceptionlessClient.Default.SubmitLog("Logging a message."); } [HttpGet] [Route("feature")] public void Feature() { - Exceptionless.ExceptionlessClient.Default.SubmitFeatureUsage("FeatureName"); + ExceptionlessClient.Default.SubmitFeatureUsage("FeatureName"); } [HttpGet] @@ -59,7 +59,7 @@ public void CustomStack() [Route("dataexclusion")] public void DataExclusion() { - Exceptionless.ExceptionlessClient.Default.Configuration.AddDataExclusions("password", "*email*"); + ExceptionlessClient.Default.Configuration.AddDataExclusions("password", "*email*"); try { @@ -77,7 +77,7 @@ public void DataExclusion() [Route("loglevel")] public void LogLevel() { - Exceptionless.ExceptionlessClient.Default.SubmitLog( + ExceptionlessClient.Default.SubmitLog( "Your log message here", Exceptionless.Logging.LogLevel.Trace); } diff --git a/dotnet-logging/Exceptionless/ExceptionlessTestClient/ExceptionlessClient.csproj b/dotnet-logging/Exceptionless/ExceptionlessTestClient/ExceptionlessClient.csproj index 3104c2258a..7e9cd8284a 100644 --- a/dotnet-logging/Exceptionless/ExceptionlessTestClient/ExceptionlessClient.csproj +++ b/dotnet-logging/Exceptionless/ExceptionlessTestClient/ExceptionlessClient.csproj @@ -1,14 +1,14 @@ - net8.0 + net11.0 enable enable - - + + diff --git a/dotnet-logging/Exceptionless/ExceptionlessTestClient/ExceptionlessTestClient.sln b/dotnet-logging/Exceptionless/ExceptionlessTestClient/ExceptionlessTestClient.sln deleted file mode 100644 index 11c6cf481e..0000000000 --- a/dotnet-logging/Exceptionless/ExceptionlessTestClient/ExceptionlessTestClient.sln +++ /dev/null @@ -1,25 +0,0 @@ - -Microsoft Visual Studio Solution File, Format Version 12.00 -# Visual Studio Version 17 -VisualStudioVersion = 17.8.34525.116 -MinimumVisualStudioVersion = 10.0.40219.1 -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ExceptionlessTestClient", "ExceptionlessTestClient.csproj", "{6F843E9B-3DD9-4C95-ADFB-68E4901187C4}" -EndProject -Global - GlobalSection(SolutionConfigurationPlatforms) = preSolution - Debug|Any CPU = Debug|Any CPU - Release|Any CPU = Release|Any CPU - EndGlobalSection - GlobalSection(ProjectConfigurationPlatforms) = postSolution - {6F843E9B-3DD9-4C95-ADFB-68E4901187C4}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {6F843E9B-3DD9-4C95-ADFB-68E4901187C4}.Debug|Any CPU.Build.0 = Debug|Any CPU - {6F843E9B-3DD9-4C95-ADFB-68E4901187C4}.Release|Any CPU.ActiveCfg = Release|Any CPU - {6F843E9B-3DD9-4C95-ADFB-68E4901187C4}.Release|Any CPU.Build.0 = Release|Any CPU - EndGlobalSection - GlobalSection(SolutionProperties) = preSolution - HideSolutionNode = FALSE - EndGlobalSection - GlobalSection(ExtensibilityGlobals) = postSolution - SolutionGuid = {1B8F338C-4E2C-4FC1-A7A7-869B0CD73BB3} - EndGlobalSection -EndGlobal diff --git a/dotnet-logging/Exceptionless/ExceptionlessTestClient/Program.cs b/dotnet-logging/Exceptionless/ExceptionlessTestClient/Program.cs index cdfcae44e4..4470957c72 100644 --- a/dotnet-logging/Exceptionless/ExceptionlessTestClient/Program.cs +++ b/dotnet-logging/Exceptionless/ExceptionlessTestClient/Program.cs @@ -3,21 +3,22 @@ var builder = WebApplication.CreateBuilder(args); builder.Services.AddControllers(); -builder.Services.AddEndpointsApiExplorer(); -builder.Services.AddSwaggerGen(); -builder.Services.AddExceptionless(); +builder.Services.AddOpenApi(); +builder.Services.AddProblemDetails(); +builder.AddExceptionless(); var app = builder.Build(); if (app.Environment.IsDevelopment()) { - app.UseSwagger(); - app.UseSwaggerUI(); + app.MapOpenApi(); } +app.UseExceptionHandler(); +app.UseExceptionless(); + app.UseHttpsRedirection(); app.UseAuthorization(); app.MapControllers(); -app.UseExceptionless(); -app.Run(); \ No newline at end of file +app.Run(); diff --git a/dotnet-logging/Exceptionless/ExceptionlessTestClient/Properties/launchSettings.json b/dotnet-logging/Exceptionless/ExceptionlessTestClient/Properties/launchSettings.json index 14fc1cefe9..79b204b6e1 100644 --- a/dotnet-logging/Exceptionless/ExceptionlessTestClient/Properties/launchSettings.json +++ b/dotnet-logging/Exceptionless/ExceptionlessTestClient/Properties/launchSettings.json @@ -4,8 +4,7 @@ "https": { "commandName": "Project", "dotnetRunMessages": true, - "launchBrowser": true, - "launchUrl": "swagger", + "launchBrowser": false, "applicationUrl": "https://localhost:7256;http://localhost:5215", "environmentVariables": { "ASPNETCORE_ENVIRONMENT": "Development" diff --git a/dotnet-logging/Exceptionless/Tests/Tests/ExceptionlessCaptureTest.cs b/dotnet-logging/Exceptionless/Tests/Tests/ExceptionlessCaptureTest.cs new file mode 100644 index 0000000000..297b4aa772 --- /dev/null +++ b/dotnet-logging/Exceptionless/Tests/Tests/ExceptionlessCaptureTest.cs @@ -0,0 +1,46 @@ +using System.Net; +using Exceptionless; +using Exceptionless.Models; +using Microsoft.AspNetCore.Hosting; +using Microsoft.AspNetCore.Mvc.Testing; + +namespace Tests; + +public class ExceptionlessCaptureTest : IClassFixture> +{ + private readonly WebApplicationFactory _factory; + + public ExceptionlessCaptureTest(WebApplicationFactory factory) + { + _factory = factory.WithWebHostBuilder(builder => + { + builder.UseSetting("Exceptionless:ApiKey", "LOCAL_TEST_KEY_NOT_REAL"); + builder.UseSetting("Exceptionless:ServerUrl", "http://localhost:9"); + }); + } + + [Fact] + public async Task GivenGetEndpoint_WhenItThrows_ThenExceptionlessCapturesAnErrorEvent() + { + var captured = new List(); + EventHandler handler = (_, e) => + { + captured.Add(e.Event); + e.Cancel = true; + }; + + ExceptionlessClient.Default.SubmittingEvent += handler; + try + { + var client = _factory.CreateClient(); + var response = await client.GetAsync("/api/values"); + + Assert.Equal(HttpStatusCode.InternalServerError, response.StatusCode); + Assert.Contains(captured, e => e.Type == Event.KnownTypes.Error); + } + finally + { + ExceptionlessClient.Default.SubmittingEvent -= handler; + } + } +} diff --git a/dotnet-logging/Exceptionless/Tests/Tests/Tests.csproj b/dotnet-logging/Exceptionless/Tests/Tests/Tests.csproj index aeeafdec0d..c5eb493f3b 100644 --- a/dotnet-logging/Exceptionless/Tests/Tests/Tests.csproj +++ b/dotnet-logging/Exceptionless/Tests/Tests/Tests.csproj @@ -1,7 +1,7 @@ - net8.0 + net11.0 enable enable @@ -10,13 +10,14 @@ - - - + + + + runtime; build; native; contentfiles; analyzers; buildtransitive all - + runtime; build; native; contentfiles; analyzers; buildtransitive all diff --git a/dotnet-logging/Exceptionless/Tests/Tests/ValuesControllerTest.cs b/dotnet-logging/Exceptionless/Tests/Tests/ValuesControllerTest.cs index d2bc1f7cf5..0521fb1c41 100644 --- a/dotnet-logging/Exceptionless/Tests/Tests/ValuesControllerTest.cs +++ b/dotnet-logging/Exceptionless/Tests/Tests/ValuesControllerTest.cs @@ -1,4 +1,4 @@ -using ExceptionlessClient.Controllers; +using ExceptionlessDemo.Controllers; namespace Tests;