-
-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added .NET 9 sample and test on .NET 9
- Loading branch information
1 parent
f045b6d
commit 5965d29
Showing
18 changed files
with
324 additions
and
2 deletions.
There are no files selected for viewing
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 |
---|---|---|
|
@@ -21,6 +21,7 @@ jobs: | |
6.0.x | ||
7.0.x | ||
8.0.x | ||
9.0.x | ||
- name: Install dependencies | ||
run: dotnet restore | ||
|
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
53 changes: 53 additions & 0 deletions
53
samples/Elmah.Io.AspNetCore90.Example/Controllers/HomeController.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,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 }); | ||
} | ||
} | ||
} |
13 changes: 13 additions & 0 deletions
13
samples/Elmah.Io.AspNetCore90.Example/Elmah.Io.AspNetCore90.Example.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,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> |
9 changes: 9 additions & 0 deletions
9
samples/Elmah.Io.AspNetCore90.Example/Models/ErrorViewModel.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,9 @@ | ||
namespace Elmah.Io.AspNetCore90.Example.Models | ||
{ | ||
public class ErrorViewModel | ||
{ | ||
public string? RequestId { get; set; } | ||
|
||
public bool ShowRequestId => !string.IsNullOrEmpty(RequestId); | ||
} | ||
} |
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,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
8
samples/Elmah.Io.AspNetCore90.Example/Views/Home/Index.cshtml
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,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> |
6 changes: 6 additions & 0 deletions
6
samples/Elmah.Io.AspNetCore90.Example/Views/Home/Privacy.cshtml
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,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
25
samples/Elmah.Io.AspNetCore90.Example/Views/Shared/Error.cshtml
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,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
50
samples/Elmah.Io.AspNetCore90.Example/Views/Shared/_Layout.cshtml
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,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"> | ||
© 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> |
48 changes: 48 additions & 0 deletions
48
samples/Elmah.Io.AspNetCore90.Example/Views/Shared/_Layout.cshtml.css
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,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; | ||
} |
2 changes: 2 additions & 0 deletions
2
samples/Elmah.Io.AspNetCore90.Example/Views/Shared/_ValidationScriptsPartial.cshtml
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,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> |
3 changes: 3 additions & 0 deletions
3
samples/Elmah.Io.AspNetCore90.Example/Views/_ViewImports.cshtml
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,3 @@ | ||
@using Elmah.Io.AspNetCore90.Example | ||
@using Elmah.Io.AspNetCore90.Example.Models | ||
@addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers |
3 changes: 3 additions & 0 deletions
3
samples/Elmah.Io.AspNetCore90.Example/Views/_ViewStart.cshtml
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,3 @@ | ||
@{ | ||
Layout = "_Layout"; | ||
} |
8 changes: 8 additions & 0 deletions
8
samples/Elmah.Io.AspNetCore90.Example/appsettings.Development.json
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,8 @@ | ||
{ | ||
"Logging": { | ||
"LogLevel": { | ||
"Default": "Information", | ||
"Microsoft.AspNetCore": "Warning" | ||
} | ||
} | ||
} |
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,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" | ||
} | ||
} |
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
2 changes: 1 addition & 1 deletion
2
test/Elmah.Io.AspNetCore.Tests/Elmah.Io.AspNetCore.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