File tree Expand file tree Collapse file tree 2 files changed +27
-0
lines changed Expand file tree Collapse file tree 2 files changed +27
-0
lines changed Original file line number Diff line number Diff line change
1
+ using Microsoft . AspNetCore . Mvc . Filters ;
2
+ using Serilog ;
3
+
4
+ namespace SerilogRequestLogging
5
+ {
6
+ public class SerilogLoggingPageFilter : IPageFilter
7
+ {
8
+ private readonly IDiagnosticContext _diagnosticContext ;
9
+ public SerilogLoggingPageFilter ( IDiagnosticContext diagnosticContext )
10
+ {
11
+ _diagnosticContext = diagnosticContext ;
12
+ }
13
+
14
+ public void OnPageHandlerSelected ( PageHandlerSelectedContext context )
15
+ {
16
+ var name = context . HandlerMethod ? . Name ?? context . HandlerMethod ? . MethodInfo . Name ;
17
+ if ( name != null )
18
+ {
19
+ _diagnosticContext . Set ( "RazorPageHandler" , name ) ;
20
+ }
21
+ }
22
+
23
+ public void OnPageHandlerExecuted ( PageHandlerExecutedContext context ) { }
24
+ public void OnPageHandlerExecuting ( PageHandlerExecutingContext context ) { }
25
+ }
26
+ }
Original file line number Diff line number Diff line change @@ -26,6 +26,7 @@ public void ConfigureServices(IServiceCollection services)
26
26
{
27
27
services . AddControllers ( opts =>
28
28
{
29
+ opts . Filters . Add < SerilogLoggingPageFilter > ( ) ;
29
30
opts . Filters . Add < SerilogLoggingActionFilter > ( ) ;
30
31
} ) ;
31
32
services . AddRazorPages ( ) ;
You can’t perform that action at this time.
0 commit comments