Skip to content

Commit

Permalink
Added .NET 9 sample and test on .NET 9
Browse files Browse the repository at this point in the history
  • Loading branch information
ThomasArdal committed Nov 15, 2024
1 parent f045b6d commit 5965d29
Show file tree
Hide file tree
Showing 18 changed files with 324 additions and 2 deletions.
1 change: 1 addition & 0 deletions .github/workflows/dotnet-core.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ jobs:
6.0.x
7.0.x
8.0.x
9.0.x
- name: Install dependencies
run: dotnet restore
Expand Down
7 changes: 7 additions & 0 deletions Elmah.Io.AspNetCore.sln
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Elmah.Io.AspNetCore70.Examp
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Elmah.Io.AspNetCore80.Example", "samples\Elmah.Io.AspNetCore80.Example\Elmah.Io.AspNetCore80.Example.csproj", "{96D3E57A-3734-4049-BAEA-E97A405AE4EE}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Elmah.Io.AspNetCore90.Example", "samples\Elmah.Io.AspNetCore90.Example\Elmah.Io.AspNetCore90.Example.csproj", "{CCD64990-D7F5-4FBD-9F37-6E3A0B8E6E02}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -72,6 +74,10 @@ Global
{96D3E57A-3734-4049-BAEA-E97A405AE4EE}.Debug|Any CPU.Build.0 = Debug|Any CPU
{96D3E57A-3734-4049-BAEA-E97A405AE4EE}.Release|Any CPU.ActiveCfg = Release|Any CPU
{96D3E57A-3734-4049-BAEA-E97A405AE4EE}.Release|Any CPU.Build.0 = Release|Any CPU
{CCD64990-D7F5-4FBD-9F37-6E3A0B8E6E02}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{CCD64990-D7F5-4FBD-9F37-6E3A0B8E6E02}.Debug|Any CPU.Build.0 = Debug|Any CPU
{CCD64990-D7F5-4FBD-9F37-6E3A0B8E6E02}.Release|Any CPU.ActiveCfg = Release|Any CPU
{CCD64990-D7F5-4FBD-9F37-6E3A0B8E6E02}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand All @@ -85,6 +91,7 @@ Global
{44812DB3-4FAD-4BF4-83D6-0807886A042B} = {AEAB4533-28CE-4CA9-9CD7-FC7FEF911204}
{C7C799CD-1C2A-4170-91B2-268060D99427} = {AEAB4533-28CE-4CA9-9CD7-FC7FEF911204}
{96D3E57A-3734-4049-BAEA-E97A405AE4EE} = {AEAB4533-28CE-4CA9-9CD7-FC7FEF911204}
{CCD64990-D7F5-4FBD-9F37-6E3A0B8E6E02} = {AEAB4533-28CE-4CA9-9CD7-FC7FEF911204}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {DAE57CF5-2DDC-4EF5-85A3-BDA571A8E9A9}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
using Elmah.Io.AspNetCore;
using Elmah.Io.AspNetCore90.Example.Models;
using Microsoft.AspNetCore.Mvc;
using System.Diagnostics;

namespace Elmah.Io.AspNetCore90.Example.Controllers
{
public class HomeController : Controller
{
private readonly ILogger<HomeController> _logger;

public HomeController(ILogger<HomeController> logger)
{
_logger = logger;
}

public IActionResult Index()
{
// Logging can be used for breadcrumbs
//_logger.LogInformation("Requesting the frontpage");

// Breadcrumbs can also be added manually
//ElmahIoApi.AddBreadcrumb(new Client.Breadcrumb(action: "Navigation", message: "Requesting the frontpage"), HttpContext);

throw new Exception("Do you know what happened to the neanderthals, Bernard? We ate them.");
}

public IActionResult Privacy()
{
try
{
var i = 0;
var result = 42 / i;
}
catch (DivideByZeroException e)
{
// Either use the Ship extension method
e.Ship(HttpContext);

// Or the Log method on ElmahIoApi
//ElmahIoApi.Log(e, HttpContext);
}

return View();
}

[ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)]
public IActionResult Error()
{
return View(new ErrorViewModel { RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier });
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<Project Sdk="Microsoft.NET.Sdk.Web">

<PropertyGroup>
<TargetFramework>net9.0</TargetFramework>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\..\src\Elmah.Io.AspNetCore\Elmah.Io.AspNetCore.csproj" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
namespace Elmah.Io.AspNetCore90.Example.Models
{
public class ErrorViewModel
{
public string? RequestId { get; set; }

public bool ShowRequestId => !string.IsNullOrEmpty(RequestId);
}
}
71 changes: 71 additions & 0 deletions samples/Elmah.Io.AspNetCore90.Example/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
var builder = WebApplication.CreateBuilder(args);

// IMPORTANT: this is where the magic happens. Insert your api key found on the profile as well as the log id of the log to log to.
builder.Services.AddElmahIo(options =>
{
options.ApiKey = "API_KEY";
options.LogId = new Guid("LOG_ID");

// Use log messages logged through Microsoft.Extensions.Logging as breadcrumbs
options.TreatLoggingAsBreadcrumbs = true;

// Filter out breadcrumbs you don't want (like some messages logged through Microsoft.Extensions.Logging)
//options.OnFilterBreadcrumb = breadcrumb => breadcrumb.Message == "A message we don't want as a breadcrumb";

// Optional application name
//options.Application = "ASP.NET Core 9.0 Application";

// Add event handlers etc. like this:
//options.OnMessage = msg =>
//{
// msg.Version = "9.0.0";
//};

// Remove comment on the following line to log through a proxy (in this case Fiddler).
//options.WebProxy = new WebProxy("localhost", 8888);
});

// ApiKey and LogId can be configured in appsettings.json as well, by calling the Configure-method instead of AddElmahIo.
//builder.Services.Configure<Elmah.Io.AspNetCore.ElmahIoOptions>(builder.Configuration.GetSection("ElmahIo"));
// Still need to call this to register all dependencies
//builder.Services.AddElmahIo();

// If you configure ApiKey and LogId through appsettings.json, you can still add event handlers, configure handled status codes, etc.
//builder.Services.Configure<Elmah.Io.AspNetCore.ElmahIoOptions>(o =>
//{
// o.OnMessage = msg =>
// {
// msg.Version = "9.0.0";
// };
//});

// Add services to the container.
builder.Services.AddControllersWithViews();

var app = builder.Build();

// Configure the HTTP request pipeline.
if (!app.Environment.IsDevelopment())
{
app.UseExceptionHandler("/Home/Error");
// The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
app.UseHsts();
}

// IMPORTANT: registers the elmah.io middleware (after registering other exception-aware middleware.
app.UseElmahIo();

app.UseHttpsRedirection();
app.UseRouting();

app.UseAuthorization();

app.MapStaticAssets();

app.MapControllerRoute(
name: "default",
pattern: "{controller=Home}/{action=Index}/{id?}")
.WithStaticAssets();


app.Run();
8 changes: 8 additions & 0 deletions samples/Elmah.Io.AspNetCore90.Example/Views/Home/Index.cshtml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
@{
ViewData["Title"] = "Home Page";
}

<div class="text-center">
<h1 class="display-4">Welcome</h1>
<p>Learn about <a href="https://learn.microsoft.com/aspnet/core">building Web apps with ASP.NET Core</a>.</p>
</div>
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
@{
ViewData["Title"] = "Privacy Policy";
}
<h1>@ViewData["Title"]</h1>

<p>Use this page to detail your site's privacy policy.</p>
25 changes: 25 additions & 0 deletions samples/Elmah.Io.AspNetCore90.Example/Views/Shared/Error.cshtml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
@model ErrorViewModel
@{
ViewData["Title"] = "Error";
}

<h1 class="text-danger">Error.</h1>
<h2 class="text-danger">An error occurred while processing your request.</h2>

@if (Model.ShowRequestId)
{
<p>
<strong>Request ID:</strong> <code>@Model.RequestId</code>
</p>
}

<h3>Development Mode</h3>
<p>
Swapping to <strong>Development</strong> environment will display more detailed information about the error that occurred.
</p>
<p>
<strong>The Development environment shouldn't be enabled for deployed applications.</strong>
It can result in displaying sensitive information from exceptions to end users.
For local debugging, enable the <strong>Development</strong> environment by setting the <strong>ASPNETCORE_ENVIRONMENT</strong> environment variable to <strong>Development</strong>
and restarting the app.
</p>
50 changes: 50 additions & 0 deletions samples/Elmah.Io.AspNetCore90.Example/Views/Shared/_Layout.cshtml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>@ViewData["Title"] - Elmah.Io.AspNetCore90.Example</title>
<script type="importmap"></script>
<link rel="stylesheet" href="~/lib/bootstrap/dist/css/bootstrap.min.css" />
<link rel="stylesheet" href="~/css/site.css" asp-append-version="true" />
<link rel="stylesheet" href="~/Elmah.Io.AspNetCore90.Example.styles.css" asp-append-version="true" />
</head>
<body>
<header>
<nav class="navbar navbar-expand-sm navbar-toggleable-sm navbar-light bg-white border-bottom box-shadow mb-3">
<div class="container-fluid">
<a class="navbar-brand" asp-area="" asp-controller="Home" asp-action="Index">Elmah.Io.AspNetCore90.Example</a>
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target=".navbar-collapse" aria-controls="navbarSupportedContent"
aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="navbar-collapse collapse d-sm-inline-flex justify-content-between">
<ul class="navbar-nav flex-grow-1">
<li class="nav-item">
<a class="nav-link text-dark" asp-area="" asp-controller="Home" asp-action="Index">Home</a>
</li>
<li class="nav-item">
<a class="nav-link text-dark" asp-area="" asp-controller="Home" asp-action="Privacy">Privacy</a>
</li>
</ul>
</div>
</div>
</nav>
</header>
<div class="container">
<main role="main" class="pb-3">
@RenderBody()
</main>
</div>

<footer class="border-top footer text-muted">
<div class="container">
&copy; 2024 - Elmah.Io.AspNetCore90.Example - <a asp-area="" asp-controller="Home" asp-action="Privacy">Privacy</a>
</div>
</footer>
<script src="~/lib/jquery/dist/jquery.min.js"></script>
<script src="~/lib/bootstrap/dist/js/bootstrap.bundle.min.js"></script>
<script src="~/js/site.js" asp-append-version="true"></script>
@await RenderSectionAsync("Scripts", required: false)
</body>
</html>
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/* Please see documentation at https://learn.microsoft.com/aspnet/core/client-side/bundling-and-minification
for details on configuring this project to bundle and minify static web assets. */

a.navbar-brand {
white-space: normal;
text-align: center;
word-break: break-all;
}

a {
color: #0077cc;
}

.btn-primary {
color: #fff;
background-color: #1b6ec2;
border-color: #1861ac;
}

.nav-pills .nav-link.active, .nav-pills .show > .nav-link {
color: #fff;
background-color: #1b6ec2;
border-color: #1861ac;
}

.border-top {
border-top: 1px solid #e5e5e5;
}
.border-bottom {
border-bottom: 1px solid #e5e5e5;
}

.box-shadow {
box-shadow: 0 .25rem .75rem rgba(0, 0, 0, .05);
}

button.accept-policy {
font-size: 1rem;
line-height: inherit;
}

.footer {
position: absolute;
bottom: 0;
width: 100%;
white-space: nowrap;
line-height: 60px;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<script src="~/lib/jquery-validation/dist/jquery.validate.min.js"></script>
<script src="~/lib/jquery-validation-unobtrusive/dist/jquery.validate.unobtrusive.min.js"></script>
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
@using Elmah.Io.AspNetCore90.Example
@using Elmah.Io.AspNetCore90.Example.Models
@addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers
3 changes: 3 additions & 0 deletions samples/Elmah.Io.AspNetCore90.Example/Views/_ViewStart.cshtml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
@{
Layout = "_Layout";
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft.AspNetCore": "Warning"
}
}
}
14 changes: 14 additions & 0 deletions samples/Elmah.Io.AspNetCore90.Example/appsettings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft.AspNetCore": "Warning"
}
},
"AllowedHosts": "*",
// The following section is only needed if configuring elmah.io using the Configure-method in ConfigureServices or Program.
"ElmahIo": {
"ApiKey": "API_KEY",
"LogId": "LOG_ID"
}
}
3 changes: 2 additions & 1 deletion samples/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@ This directory contains samples to show how to integrate elmah.io into ASP.NET C
* **Elmah.Io.AspNetCore.HealthChecks.Example** - Shows how to integrate ASP.NET Core Health Checks with elmah.io.
* **Elmah.Io.AspNetCore60.Example** - Integrate elmah.io into ASP.NET Core v6.0.
* **Elmah.Io.AspNetCore70.Example** - Integrate elmah.io into ASP.NET Core v7.0.
* **Elmah.Io.AspNetCore80.Example** - Integrate elmah.io into ASP.NET Core v8.0.
* **Elmah.Io.AspNetCore80.Example** - Integrate elmah.io into ASP.NET Core v8.0.
* **Elmah.Io.AspNetCore90.Example** - Integrate elmah.io into ASP.NET Core v9.0.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>net6.0;net7.0;net8.0</TargetFrameworks>
<TargetFrameworks>net6.0;net7.0;net8.0;net9.0</TargetFrameworks>
<AssemblyName>Elmah.Io.AspNetCore.Tests</AssemblyName>
<PackageId>Elmah.Io.AspNetCore.Tests</PackageId>
<GenerateRuntimeConfigurationFiles>true</GenerateRuntimeConfigurationFiles>
Expand Down

0 comments on commit 5965d29

Please sign in to comment.