Skip to content
This repository was archived by the owner on Oct 2, 2024. It is now read-only.

Commit a848369

Browse files
tsimbalarTwan Jacobs
andauthored
Ensure exception gets logged when CustomErrors mode is On (#13)
Ensure exception gets logged when CustomErrors mode is On Co-authored-by: Twan Jacobs <tjacobs@routit.com>
2 parents e682255 + 2d2dcd9 commit a848369

File tree

6 files changed

+27
-4
lines changed

6 files changed

+27
-4
lines changed

src/SerilogWeb.Classic.Mvc/Classic/Mvc/PreApplicationStartModule.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ public class PreApplicationStartModule
77
public static void Register()
88
{
99
GlobalFilters.Filters.Add(new StoreMvcInfoInHttpContextActionFilter());
10+
GlobalFilters.Filters.Add(new SerilogWebClassicExceptionFilter());
1011
}
1112
}
1213
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
using System;
2+
using System.Web.Mvc;
3+
using SerilogWeb.Classic.Extensions;
4+
5+
namespace SerilogWeb.Classic.Mvc
6+
{
7+
internal class SerilogWebClassicExceptionFilter : IExceptionFilter
8+
{
9+
public void OnException(ExceptionContext filterContext)
10+
{
11+
if (filterContext.ExceptionHandled || filterContext.HttpContext.IsCustomErrorEnabled)
12+
{
13+
var exception = filterContext.Exception;
14+
if (exception != null)
15+
{
16+
filterContext.HttpContext.AddSerilogWebError(exception);
17+
}
18+
}
19+
}
20+
}
21+
}

src/SerilogWeb.Classic.Mvc/SerilogWeb.Classic.Mvc.csproj

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@
4444
<HintPath>..\..\packages\Serilog.2.7.1\lib\net45\Serilog.dll</HintPath>
4545
</Reference>
4646
<Reference Include="SerilogWeb.Classic, Version=5.0.0.0, Culture=neutral, PublicKeyToken=9462ddd55fbc0e7f, processorArchitecture=MSIL">
47-
<HintPath>..\..\packages\SerilogWeb.Classic.5.0.48\lib\net45\SerilogWeb.Classic.dll</HintPath>
47+
<HintPath>..\..\packages\SerilogWeb.Classic.5.0.52\lib\net45\SerilogWeb.Classic.dll</HintPath>
4848
</Reference>
4949
<Reference Include="System" />
5050
<Reference Include="System.Core" />
@@ -85,6 +85,7 @@
8585
<Compile Include="Classic\Mvc\Enrichers\MvcRouteDataEnricher.cs" />
8686
<Compile Include="Classic\Mvc\Enrichers\MvcRouteTemplateEnricher.cs" />
8787
<Compile Include="Classic\Mvc\PreApplicationStartModule.cs" />
88+
<Compile Include="Classic\Mvc\SerilogWebClassicExceptionFilter.cs" />
8889
<Compile Include="Classic\Mvc\StoreMvcInfoInHttpContextActionFilter.cs" />
8990
<Compile Include="Classic\Mvc\MvcRequestInfoKey.cs" />
9091
<Compile Include="Properties\AssemblyInfo.cs" />

src/SerilogWeb.Classic.Mvc/packages.config

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,5 @@
55
<package id="Microsoft.AspNet.WebPages" version="3.2.3" targetFramework="net45" />
66
<package id="Microsoft.Web.Infrastructure" version="1.0.0.0" targetFramework="net45" />
77
<package id="Serilog" version="2.7.1" targetFramework="net45" />
8-
<package id="SerilogWeb.Classic" version="5.0.48" targetFramework="net45" />
8+
<package id="SerilogWeb.Classic" version="5.0.52" targetFramework="net45" />
99
</packages>

test/SerilogWeb.Classic.Mvc.Test/SerilogWeb.Classic.Mvc.Test.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@
7171
<HintPath>..\..\packages\Serilog.Sinks.Trace.2.1.0\lib\net45\Serilog.Sinks.Trace.dll</HintPath>
7272
</Reference>
7373
<Reference Include="SerilogWeb.Classic, Version=5.0.0.0, Culture=neutral, PublicKeyToken=9462ddd55fbc0e7f, processorArchitecture=MSIL">
74-
<HintPath>..\..\packages\SerilogWeb.Classic.5.0.48\lib\net45\SerilogWeb.Classic.dll</HintPath>
74+
<HintPath>..\..\packages\SerilogWeb.Classic.5.0.52\lib\net45\SerilogWeb.Classic.dll</HintPath>
7575
</Reference>
7676
<Reference Include="System" />
7777
<Reference Include="System.Data" />

test/SerilogWeb.Classic.Mvc.Test/packages.config

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,6 @@
1818
<package id="Serilog" version="2.7.1" targetFramework="net45" />
1919
<package id="Serilog.Settings.AppSettings" version="2.1.2" targetFramework="net45" />
2020
<package id="Serilog.Sinks.Trace" version="2.1.0" targetFramework="net45" />
21-
<package id="SerilogWeb.Classic" version="5.0.48" targetFramework="net45" />
21+
<package id="SerilogWeb.Classic" version="5.0.52" targetFramework="net45" />
2222
<package id="WebGrease" version="1.5.2" targetFramework="net45" />
2323
</packages>

0 commit comments

Comments
 (0)