Skip to content

Commit 97bb00b

Browse files
committed
Show exception detail and properites via modal.
1 parent 51321e9 commit 97bb00b

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

57 files changed

+39744
-18
lines changed

Serilog.Ui.sln

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,12 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{ACA69857-2E3
77
EndProject
88
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Serilog.Ui.Web", "src\Serilog.Ui.Web\Serilog.Ui.Web.csproj", "{3BF751F9-67CA-47F2-84E0-068344A8F306}"
99
EndProject
10-
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SampleWebApplication", "src\SampleWebApplication\SampleWebApplication.csproj", "{F1729252-4E41-4A79-8F89-560922668E87}"
11-
EndProject
1210
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Serilog.Ui.MsSqlServerProvider", "src\Serilog.Ui.MsSqlServerProvider\Serilog.Ui.MsSqlServerProvider.csproj", "{55C49567-1879-4FA7-B15F-033DA89B8B1B}"
1311
EndProject
1412
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Serilog.Ui.Core", "src\Serilog.Ui.Core\Serilog.Ui.Core.csproj", "{0862FA16-35A3-4CF9-B797-67F70F6CFB8B}"
1513
EndProject
14+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SampleWebApplication", "src\SampleWebApplication\SampleWebApplication.csproj", "{BFC83C68-698A-4818-9C5A-ADE9C91DBE9E}"
15+
EndProject
1616
Global
1717
GlobalSection(SolutionConfigurationPlatforms) = preSolution
1818
Debug|Any CPU = Debug|Any CPU
@@ -23,10 +23,6 @@ Global
2323
{3BF751F9-67CA-47F2-84E0-068344A8F306}.Debug|Any CPU.Build.0 = Debug|Any CPU
2424
{3BF751F9-67CA-47F2-84E0-068344A8F306}.Release|Any CPU.ActiveCfg = Release|Any CPU
2525
{3BF751F9-67CA-47F2-84E0-068344A8F306}.Release|Any CPU.Build.0 = Release|Any CPU
26-
{F1729252-4E41-4A79-8F89-560922668E87}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
27-
{F1729252-4E41-4A79-8F89-560922668E87}.Debug|Any CPU.Build.0 = Debug|Any CPU
28-
{F1729252-4E41-4A79-8F89-560922668E87}.Release|Any CPU.ActiveCfg = Release|Any CPU
29-
{F1729252-4E41-4A79-8F89-560922668E87}.Release|Any CPU.Build.0 = Release|Any CPU
3026
{55C49567-1879-4FA7-B15F-033DA89B8B1B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
3127
{55C49567-1879-4FA7-B15F-033DA89B8B1B}.Debug|Any CPU.Build.0 = Debug|Any CPU
3228
{55C49567-1879-4FA7-B15F-033DA89B8B1B}.Release|Any CPU.ActiveCfg = Release|Any CPU
@@ -35,15 +31,19 @@ Global
3531
{0862FA16-35A3-4CF9-B797-67F70F6CFB8B}.Debug|Any CPU.Build.0 = Debug|Any CPU
3632
{0862FA16-35A3-4CF9-B797-67F70F6CFB8B}.Release|Any CPU.ActiveCfg = Release|Any CPU
3733
{0862FA16-35A3-4CF9-B797-67F70F6CFB8B}.Release|Any CPU.Build.0 = Release|Any CPU
34+
{BFC83C68-698A-4818-9C5A-ADE9C91DBE9E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
35+
{BFC83C68-698A-4818-9C5A-ADE9C91DBE9E}.Debug|Any CPU.Build.0 = Debug|Any CPU
36+
{BFC83C68-698A-4818-9C5A-ADE9C91DBE9E}.Release|Any CPU.ActiveCfg = Release|Any CPU
37+
{BFC83C68-698A-4818-9C5A-ADE9C91DBE9E}.Release|Any CPU.Build.0 = Release|Any CPU
3838
EndGlobalSection
3939
GlobalSection(SolutionProperties) = preSolution
4040
HideSolutionNode = FALSE
4141
EndGlobalSection
4242
GlobalSection(NestedProjects) = preSolution
4343
{3BF751F9-67CA-47F2-84E0-068344A8F306} = {ACA69857-2E3E-468C-B0B0-A86852E3492D}
44-
{F1729252-4E41-4A79-8F89-560922668E87} = {ACA69857-2E3E-468C-B0B0-A86852E3492D}
4544
{55C49567-1879-4FA7-B15F-033DA89B8B1B} = {ACA69857-2E3E-468C-B0B0-A86852E3492D}
4645
{0862FA16-35A3-4CF9-B797-67F70F6CFB8B} = {ACA69857-2E3E-468C-B0B0-A86852E3492D}
46+
{BFC83C68-698A-4818-9C5A-ADE9C91DBE9E} = {ACA69857-2E3E-468C-B0B0-A86852E3492D}
4747
EndGlobalSection
4848
GlobalSection(ExtensibilityGlobals) = postSolution
4949
SolutionGuid = {88374732-FEAD-4375-9CF1-75331A37CF07}
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
using Microsoft.AspNetCore.Mvc;
2+
using Microsoft.Extensions.Logging;
3+
using SampleWebApplication.Models;
4+
using System.Diagnostics;
5+
6+
namespace SampleWebApplication.Controllers
7+
{
8+
public class HomeController : Controller
9+
{
10+
private readonly ILogger<HomeController> _logger;
11+
12+
public HomeController(ILogger<HomeController> logger)
13+
{
14+
_logger = logger;
15+
}
16+
17+
public IActionResult Index(int? id)
18+
{
19+
//if (id == null)
20+
//{
21+
// try
22+
// {
23+
// throw new ArgumentNullException(nameof(id));
24+
// }
25+
// catch (Exception e)
26+
// {
27+
// _logger.LogError(e, e.Message);
28+
// }
29+
//}
30+
31+
return View();
32+
}
33+
34+
public IActionResult Privacy()
35+
{
36+
_logger.LogWarning("Privacy api was called.");
37+
38+
return View();
39+
}
40+
41+
[ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)]
42+
public IActionResult Error()
43+
{
44+
return View(new ErrorViewModel { RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier });
45+
}
46+
}
47+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
using System;
2+
3+
namespace SampleWebApplication.Models
4+
{
5+
public class ErrorViewModel
6+
{
7+
public string RequestId { get; set; }
8+
9+
public bool ShowRequestId => !string.IsNullOrEmpty(RequestId);
10+
}
11+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
using Microsoft.AspNetCore.Hosting;
2+
using Microsoft.Extensions.Hosting;
3+
using Serilog;
4+
5+
namespace SampleWebApplication
6+
{
7+
public class Program
8+
{
9+
public static void Main(string[] args)
10+
{
11+
CreateHostBuilder(args).Build().Run();
12+
}
13+
14+
public static IHostBuilder CreateHostBuilder(string[] args) =>
15+
Host.CreateDefaultBuilder(args)
16+
.ConfigureWebHostDefaults(webBuilder =>
17+
{
18+
webBuilder.UseStartup<Startup>();
19+
})
20+
.UseSerilog();
21+
}
22+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
{
2+
"iisSettings": {
3+
"windowsAuthentication": false,
4+
"anonymousAuthentication": true,
5+
"iisExpress": {
6+
"applicationUrl": "http://localhost:57024",
7+
"sslPort": 44386
8+
}
9+
},
10+
"profiles": {
11+
"IIS Express": {
12+
"commandName": "IISExpress",
13+
"launchBrowser": true,
14+
"environmentVariables": {
15+
"ASPNETCORE_ENVIRONMENT": "Development"
16+
}
17+
},
18+
"SampleWebApplication": {
19+
"commandName": "Project",
20+
"launchBrowser": true,
21+
"applicationUrl": "https://localhost:5001;http://localhost:5000",
22+
"environmentVariables": {
23+
"ASPNETCORE_ENVIRONMENT": "Development"
24+
}
25+
}
26+
}
27+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<Project Sdk="Microsoft.NET.Sdk.Web">
2+
3+
<PropertyGroup>
4+
<TargetFramework>netcoreapp3.1</TargetFramework>
5+
</PropertyGroup>
6+
7+
<ItemGroup>
8+
<PackageReference Include="Serilog.AspNetCore" Version="3.2.0" />
9+
<PackageReference Include="Serilog.Sinks.MSSqlServer" Version="5.2.0" />
10+
</ItemGroup>
11+
12+
<ItemGroup>
13+
<ProjectReference Include="..\Serilog.Ui.MsSqlServerProvider\Serilog.Ui.MsSqlServerProvider.csproj" />
14+
<ProjectReference Include="..\Serilog.Ui.Web\Serilog.Ui.Web.csproj" />
15+
</ItemGroup>
16+
17+
</Project>
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
using Microsoft.AspNetCore.Builder;
2+
using Microsoft.AspNetCore.Hosting;
3+
using Microsoft.Extensions.Configuration;
4+
using Microsoft.Extensions.DependencyInjection;
5+
using Microsoft.Extensions.Hosting;
6+
using Serilog;
7+
using Serilog.Events;
8+
using Serilog.Ui.MsSqlServerProvider;
9+
using Serilog.Ui.Web;
10+
11+
namespace SampleWebApplication
12+
{
13+
public class Startup
14+
{
15+
public Startup(IConfiguration configuration)
16+
{
17+
Log.Logger = new LoggerConfiguration()
18+
.WriteTo
19+
.MSSqlServer("Server=.;Database=SerilogWebUi;Integrated Security=True;", "Logs")
20+
.MinimumLevel.Override("Microsoft", LogEventLevel.Error)
21+
.MinimumLevel.Override("System", LogEventLevel.Error)
22+
.CreateLogger();
23+
24+
Configuration = configuration;
25+
}
26+
27+
public IConfiguration Configuration { get; }
28+
29+
// This method gets called by the runtime. Use this method to add services to the container.
30+
public void ConfigureServices(IServiceCollection services)
31+
{
32+
var mvcBuilder = services.AddControllersWithViews();
33+
34+
services.AddSerilogUi(mvcBuilder, options =>
35+
options.UseSqlServer("Server=.;Database=SerilogWebUi;Integrated Security=True;", "Logs"));
36+
}
37+
38+
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
39+
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
40+
{
41+
if (env.IsDevelopment())
42+
{
43+
app.UseDeveloperExceptionPage();
44+
}
45+
else
46+
{
47+
app.UseExceptionHandler("/Home/Error");
48+
// The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
49+
app.UseHsts();
50+
}
51+
app.UseHttpsRedirection();
52+
app.UseStaticFiles();
53+
54+
app.UseRouting();
55+
56+
app.UseAuthorization();
57+
58+
app.UseEndpoints(endpoints =>
59+
{
60+
endpoints.MapControllerRoute(
61+
name: "default",
62+
pattern: "{controller=Home}/{action=Index}/{id?}");
63+
});
64+
}
65+
}
66+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
@{
2+
ViewData["Title"] = "Home Page";
3+
}
4+
5+
<div class="text-center">
6+
<h1 class="display-4">Welcome</h1>
7+
<p>Learn about <a href="https://docs.microsoft.com/aspnet/core">building Web apps with ASP.NET Core</a>.</p>
8+
</div>
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
@{
2+
ViewData["Title"] = "Privacy Policy";
3+
}
4+
<h1>@ViewData["Title"]</h1>
5+
6+
<p>Use this page to detail your site's privacy policy.</p>
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
@model ErrorViewModel
2+
@{
3+
ViewData["Title"] = "Error";
4+
}
5+
6+
<h1 class="text-danger">Error.</h1>
7+
<h2 class="text-danger">An error occurred while processing your request.</h2>
8+
9+
@if (Model.ShowRequestId)
10+
{
11+
<p>
12+
<strong>Request ID:</strong> <code>@Model.RequestId</code>
13+
</p>
14+
}
15+
16+
<h3>Development Mode</h3>
17+
<p>
18+
Swapping to <strong>Development</strong> environment will display more detailed information about the error that occurred.
19+
</p>
20+
<p>
21+
<strong>The Development environment shouldn't be enabled for deployed applications.</strong>
22+
It can result in displaying sensitive information from exceptions to end users.
23+
For local debugging, enable the <strong>Development</strong> environment by setting the <strong>ASPNETCORE_ENVIRONMENT</strong> environment variable to <strong>Development</strong>
24+
and restarting the app.
25+
</p>

0 commit comments

Comments
 (0)