This repository has been archived by the owner on Dec 14, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
/
MvcCoreLoggerExtensions.cs
1677 lines (1434 loc) · 75 KB
/
MvcCoreLoggerExtensions.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Security.Claims;
using System.Text;
using Microsoft.AspNetCore.Mvc.Abstractions;
using Microsoft.AspNetCore.Mvc.ActionConstraints;
using Microsoft.AspNetCore.Mvc.ApplicationModels;
using Microsoft.AspNetCore.Mvc.Controllers;
using Microsoft.AspNetCore.Mvc.Filters;
using Microsoft.AspNetCore.Mvc.Formatters;
using Microsoft.AspNetCore.Mvc.Formatters.Internal;
using Microsoft.AspNetCore.Mvc.ModelBinding;
using Microsoft.AspNetCore.Mvc.ModelBinding.Metadata;
using Microsoft.Extensions.Internal;
using Microsoft.Extensions.Logging;
using Microsoft.Net.Http.Headers;
namespace Microsoft.AspNetCore.Mvc.Internal
{
internal static class MvcCoreLoggerExtensions
{
public const string ActionFilter = "Action Filter";
private static readonly string[] _noFilters = new[] { "None" };
private static readonly double TimestampToTicks = TimeSpan.TicksPerSecond / (double)Stopwatch.Frequency;
private static readonly Action<ILogger, string, string, Exception> _actionExecuting;
private static readonly Action<ILogger, string, double, Exception> _actionExecuted;
private static readonly Action<ILogger, string, string, Exception> _pageExecuting;
private static readonly Action<ILogger, string, double, Exception> _pageExecuted;
private static readonly Action<ILogger, string[], Exception> _challengeResultExecuting;
private static readonly Action<ILogger, string, Exception> _contentResultExecuting;
private static readonly Action<ILogger, string, ModelValidationState, Exception> _actionMethodExecuting;
private static readonly Action<ILogger, string, string[], ModelValidationState, Exception> _actionMethodExecutingWithArguments;
private static readonly Action<ILogger, string, string, double, Exception> _actionMethodExecuted;
private static readonly Action<ILogger, string, string[], Exception> _logFilterExecutionPlan;
private static readonly Action<ILogger, string, string, Type, Exception> _beforeExecutingMethodOnFilter;
private static readonly Action<ILogger, string, string, Type, Exception> _afterExecutingMethodOnFilter;
private static readonly Action<ILogger, Type, Exception> _beforeExecutingActionResult;
private static readonly Action<ILogger, Type, Exception> _afterExecutingActionResult;
private static readonly Action<ILogger, string, Exception> _ambiguousActions;
private static readonly Action<ILogger, string, string, IActionConstraint, Exception> _constraintMismatch;
private static readonly Action<ILogger, FileResult, string, string, Exception> _executingFileResult;
private static readonly Action<ILogger, FileResult, string, Exception> _executingFileResultWithNoFileName;
private static readonly Action<ILogger, Exception> _notEnabledForRangeProcessing;
private static readonly Action<ILogger, Exception> _writingRangeToBody;
private static readonly Action<ILogger, object, Exception> _authorizationFailure;
private static readonly Action<ILogger, object, Exception> _resourceFilterShortCircuit;
private static readonly Action<ILogger, object, Exception> _resultFilterShortCircuit;
private static readonly Action<ILogger, object, Exception> _actionFilterShortCircuit;
private static readonly Action<ILogger, object, Exception> _exceptionFilterShortCircuit;
private static readonly Action<ILogger, string[], Exception> _forbidResultExecuting;
private static readonly Action<ILogger, string, ClaimsPrincipal, Exception> _signInResultExecuting;
private static readonly Action<ILogger, string[], Exception> _signOutResultExecuting;
private static readonly Action<ILogger, int, Exception> _httpStatusCodeResultExecuting;
private static readonly Action<ILogger, string, Exception> _localRedirectResultExecuting;
private static readonly Action<ILogger, string, Exception> _objectResultExecuting;
private static readonly Action<ILogger, string, Exception> _noFormatter;
private static readonly Action<ILogger, IOutputFormatter, string, Exception> _formatterSelected;
private static readonly Action<ILogger, string, Exception> _skippedContentNegotiation;
private static readonly Action<ILogger, Exception> _noAcceptForNegotiation;
private static readonly Action<ILogger, IEnumerable<MediaTypeSegmentWithQuality>, Exception> _noFormatterFromNegotiation;
private static readonly Action<ILogger, IInputFormatter, string, Exception> _inputFormatterSelected;
private static readonly Action<ILogger, IInputFormatter, string, Exception> _inputFormatterRejected;
private static readonly Action<ILogger, string, Exception> _noInputFormatterSelected;
private static readonly Action<ILogger, string, string, Exception> _removeFromBodyAttribute;
private static readonly Action<ILogger, string, Exception> _redirectResultExecuting;
private static readonly Action<ILogger, string, Exception> _redirectToActionResultExecuting;
private static readonly Action<ILogger, string, string, Exception> _redirectToRouteResultExecuting;
private static readonly Action<ILogger, string[], Exception> _noActionsMatched;
private static readonly Action<ILogger, string, Exception> _redirectToPageResultExecuting;
private static readonly Action<ILogger, Exception> _featureNotFound;
private static readonly Action<ILogger, Exception> _featureIsReadOnly;
private static readonly Action<ILogger, string, Exception> _maxRequestBodySizeSet;
private static readonly Action<ILogger, Exception> _requestBodySizeLimitDisabled;
private static readonly Action<ILogger, Exception> _cannotApplyRequestFormLimits;
private static readonly Action<ILogger, Exception> _appliedRequestFormLimits;
private static readonly Action<ILogger, Exception> _modelStateInvalidFilterExecuting;
private static readonly Action<ILogger, MethodInfo, string, string, Exception> _inferredParameterSource;
private static readonly Action<ILogger, IModelBinderProvider[], Exception> _registeredModelBinderProviders;
private static readonly Action<ILogger, string, Type, string, Type, Exception> _foundNoValueForPropertyInRequest;
private static readonly Action<ILogger, string, string, Type, Exception> _foundNoValueForParameterInRequest;
private static readonly Action<ILogger, string, Type, Exception> _foundNoValueInRequest;
private static readonly Action<ILogger, Type, string, Exception> _parameterBinderRequestPredicateShortCircuitOfProperty;
private static readonly Action<ILogger, string, Exception> _parameterBinderRequestPredicateShortCircuitOfParameter;
private static readonly Action<ILogger, string, Type, Exception> _noPublicSettableProperties;
private static readonly Action<ILogger, Type, Exception> _cannotBindToComplexType;
private static readonly Action<ILogger, string, Type, Exception> _cannotBindToFilesCollectionDueToUnsupportedContentType;
private static readonly Action<ILogger, Type, Exception> _cannotCreateHeaderModelBinder;
private static readonly Action<ILogger, Type, Exception> _cannotCreateHeaderModelBinderCompatVersion_2_0;
private static readonly Action<ILogger, Exception> _noFilesFoundInRequest;
private static readonly Action<ILogger, string, string, Exception> _noNonIndexBasedFormatFoundForCollection;
private static readonly Action<ILogger, string, string, string, string, string, string, Exception> _attemptingToBindCollectionUsingIndices;
private static readonly Action<ILogger, string, string, string, string, string, string, Exception> _attemptingToBindCollectionOfKeyValuePair;
private static readonly Action<ILogger, string, string, string, Exception> _noKeyValueFormatForDictionaryModelBinder;
private static readonly Action<ILogger, string, Type, string, Exception> _attemptingToBindParameterModel;
private static readonly Action<ILogger, string, Type, Exception> _doneAttemptingToBindParameterModel;
private static readonly Action<ILogger, Type, string, Type, string, Exception> _attemptingToBindPropertyModel;
private static readonly Action<ILogger, Type, string, Type, Exception> _doneAttemptingToBindPropertyModel;
private static readonly Action<ILogger, Type, string, Exception> _attemptingToBindModel;
private static readonly Action<ILogger, Type, string, Exception> _doneAttemptingToBindModel;
private static readonly Action<ILogger, string, Type, Exception> _attemptingToBindParameter;
private static readonly Action<ILogger, string, Type, Exception> _doneAttemptingToBindParameter;
private static readonly Action<ILogger, Type, string, Type, Exception> _attemptingToBindProperty;
private static readonly Action<ILogger, Type, string, Type, Exception> _doneAttemptingToBindProperty;
private static readonly Action<ILogger, Type, string, Type, Exception> _attemptingToValidateProperty;
private static readonly Action<ILogger, Type, string, Type, Exception> _doneAttemptingToValidateProperty;
private static readonly Action<ILogger, string, Type, Exception> _attemptingToValidateParameter;
private static readonly Action<ILogger, string, Type, Exception> _doneAttemptingToValidateParameter;
private static readonly Action<ILogger, string, Exception> _unsupportedFormatFilterContentType;
private static readonly Action<ILogger, string, MediaTypeCollection, Exception> _actionDoesNotSupportFormatFilterContentType;
private static readonly Action<ILogger, string, Exception> _cannotApplyFormatFilterContentType;
private static readonly Action<ILogger, Exception> _actionDoesNotExplicitlySpecifyContentTypes;
private static readonly Action<ILogger, IEnumerable<MediaTypeSegmentWithQuality>, Exception> _selectingOutputFormatterUsingAcceptHeader;
private static readonly Action<ILogger, EntityTagHeaderValue, Exception> _ifMatchPreconditionFailed;
private static readonly Action<ILogger, DateTimeOffset?, DateTimeOffset?, Exception> _ifUnmodifiedSincePreconditionFailed;
private static readonly Action<ILogger, DateTimeOffset?, DateTimeOffset?, Exception> _ifRangeLastModifiedPreconditionFailed;
private static readonly Action<ILogger, EntityTagHeaderValue, EntityTagHeaderValue, Exception> _ifRangeETagPreconditionFailed;
private static readonly Action<ILogger, IEnumerable<MediaTypeSegmentWithQuality>, MediaTypeCollection, Exception> _selectingOutputFormatterUsingAcceptHeaderAndExplicitContentTypes;
private static readonly Action<ILogger, Exception> _selectingOutputFormatterWithoutUsingContentTypes;
private static readonly Action<ILogger, MediaTypeCollection, Exception> _selectingOutputFormatterUsingContentTypes;
private static readonly Action<ILogger, Exception> _selectingFirstCanWriteFormatter;
private static readonly Action<ILogger, Type, Type, Type, Exception> _notMostEffectiveFilter;
private static readonly Action<ILogger, IEnumerable<IOutputFormatter>, Exception> _registeredOutputFormatters;
private static readonly Action<ILogger, Type, int?, Type, Exception> _transformingClientError;
static MvcCoreLoggerExtensions()
{
_actionExecuting = LoggerMessage.Define<string, string>(
LogLevel.Information,
1,
"Route matched with {RouteData}. Executing action {ActionName}");
_actionExecuted = LoggerMessage.Define<string, double>(
LogLevel.Information,
2,
"Executed action {ActionName} in {ElapsedMilliseconds}ms");
_pageExecuting = LoggerMessage.Define<string, string>(
LogLevel.Information,
3,
"Route matched with {RouteData}. Executing page {PageName}");
_pageExecuted = LoggerMessage.Define<string, double>(
LogLevel.Information,
4,
"Executed page {PageName} in {ElapsedMilliseconds}ms");
_challengeResultExecuting = LoggerMessage.Define<string[]>(
LogLevel.Information,
1,
"Executing ChallengeResult with authentication schemes ({Schemes}).");
_contentResultExecuting = LoggerMessage.Define<string>(
LogLevel.Information,
1,
"Executing ContentResult with HTTP Response ContentType of {ContentType}");
_actionMethodExecuting = LoggerMessage.Define<string, ModelValidationState>(
LogLevel.Information,
1,
"Executing action method {ActionName} - Validation state: {ValidationState}");
_actionMethodExecutingWithArguments = LoggerMessage.Define<string, string[], ModelValidationState>(
LogLevel.Information,
1,
"Executing action method {ActionName} with arguments ({Arguments}) - Validation state: {ValidationState}");
_actionMethodExecuted = LoggerMessage.Define<string, string, double>(
LogLevel.Information,
2,
"Executed action method {ActionName}, returned result {ActionResult} in {ElapsedMilliseconds}ms.");
_logFilterExecutionPlan = LoggerMessage.Define<string, string[]>(
LogLevel.Debug,
1,
"Execution plan of {FilterType} filters (in the following order): {Filters}");
_beforeExecutingMethodOnFilter = LoggerMessage.Define<string, string, Type>(
LogLevel.Trace,
2,
"{FilterType}: Before executing {Method} on filter {Filter}.");
_afterExecutingMethodOnFilter = LoggerMessage.Define<string, string, Type>(
LogLevel.Trace,
3,
"{FilterType}: After executing {Method} on filter {Filter}.");
_beforeExecutingActionResult = LoggerMessage.Define<Type>(
LogLevel.Trace,
4,
"Before executing action result {ActionResult}.");
_afterExecutingActionResult = LoggerMessage.Define<Type>(
LogLevel.Trace,
5,
"After executing action result {ActionResult}.");
_ambiguousActions = LoggerMessage.Define<string>(
LogLevel.Error,
1,
"Request matched multiple actions resulting in ambiguity. Matching actions: {AmbiguousActions}");
_constraintMismatch = LoggerMessage.Define<string, string, IActionConstraint>(
LogLevel.Debug,
2,
"Action '{ActionName}' with id '{ActionId}' did not match the constraint '{ActionConstraint}'");
_executingFileResult = LoggerMessage.Define<FileResult, string, string>(
LogLevel.Information,
1,
"Executing {FileResultType}, sending file '{FileDownloadPath}' with download name '{FileDownloadName}' ...");
_executingFileResultWithNoFileName = LoggerMessage.Define<FileResult, string>(
LogLevel.Information,
2,
"Executing {FileResultType}, sending file with download name '{FileDownloadName}' ...");
_authorizationFailure = LoggerMessage.Define<object>(
LogLevel.Information,
3,
"Authorization failed for the request at filter '{AuthorizationFilter}'.");
_resourceFilterShortCircuit = LoggerMessage.Define<object>(
LogLevel.Debug,
4,
"Request was short circuited at resource filter '{ResourceFilter}'.");
_resultFilterShortCircuit = LoggerMessage.Define<object>(
LogLevel.Debug,
5,
"Request was short circuited at result filter '{ResultFilter}'.");
_actionFilterShortCircuit = LoggerMessage.Define<object>(
LogLevel.Debug,
3,
"Request was short circuited at action filter '{ActionFilter}'.");
_exceptionFilterShortCircuit = LoggerMessage.Define<object>(
LogLevel.Debug,
4,
"Request was short circuited at exception filter '{ExceptionFilter}'.");
_forbidResultExecuting = LoggerMessage.Define<string[]>(
LogLevel.Information,
eventId: 1,
formatString: $"Executing {nameof(ForbidResult)} with authentication schemes ({{Schemes}}).");
_signInResultExecuting = LoggerMessage.Define<string, ClaimsPrincipal>(
LogLevel.Information,
eventId: 1,
formatString: $"Executing {nameof(SignInResult)} with authentication scheme ({{Scheme}}) and the following principal: {{Principal}}.");
_signOutResultExecuting = LoggerMessage.Define<string[]>(
LogLevel.Information,
eventId: 1,
formatString: $"Executing {nameof(SignOutResult)} with authentication schemes ({{Schemes}}).");
_httpStatusCodeResultExecuting = LoggerMessage.Define<int>(
LogLevel.Information,
1,
"Executing HttpStatusCodeResult, setting HTTP status code {StatusCode}");
_localRedirectResultExecuting = LoggerMessage.Define<string>(
LogLevel.Information,
1,
"Executing LocalRedirectResult, redirecting to {Destination}.");
_noFormatter = LoggerMessage.Define<string>(
LogLevel.Warning,
1,
"No output formatter was found for content type '{ContentType}' to write the response.");
_objectResultExecuting = LoggerMessage.Define<string>(
LogLevel.Information,
1,
"Executing ObjectResult, writing value of type '{Type}'.");
_formatterSelected = LoggerMessage.Define<IOutputFormatter, string>(
LogLevel.Debug,
2,
"Selected output formatter '{OutputFormatter}' and content type '{ContentType}' to write the response.");
_skippedContentNegotiation = LoggerMessage.Define<string>(
LogLevel.Debug,
3,
"Skipped content negotiation as content type '{ContentType}' is explicitly set for the response.");
_noAcceptForNegotiation = LoggerMessage.Define(
LogLevel.Debug,
4,
"No information found on request to perform content negotiation.");
_noFormatterFromNegotiation = LoggerMessage.Define<IEnumerable<MediaTypeSegmentWithQuality>>(
LogLevel.Debug,
5,
"Could not find an output formatter based on content negotiation. Accepted types were ({AcceptTypes})");
_inputFormatterSelected = LoggerMessage.Define<IInputFormatter, string>(
LogLevel.Debug,
1,
"Selected input formatter '{InputFormatter}' for content type '{ContentType}'.");
_inputFormatterRejected = LoggerMessage.Define<IInputFormatter, string>(
LogLevel.Debug,
2,
"Rejected input formatter '{InputFormatter}' for content type '{ContentType}'.");
_noInputFormatterSelected = LoggerMessage.Define<string>(
LogLevel.Debug,
3,
"No input formatter was found to support the content type '{ContentType}' for use with the [FromBody] attribute.");
_removeFromBodyAttribute = LoggerMessage.Define<string, string>(
LogLevel.Debug,
4,
"To use model binding, remove the [FromBody] attribute from the property or parameter named '{ModelName}' with model type '{ModelType}'.");
_redirectResultExecuting = LoggerMessage.Define<string>(
LogLevel.Information,
1,
"Executing RedirectResult, redirecting to {Destination}.");
_redirectToActionResultExecuting = LoggerMessage.Define<string>(
LogLevel.Information,
1,
"Executing RedirectResult, redirecting to {Destination}.");
_redirectToRouteResultExecuting = LoggerMessage.Define<string, string>(
LogLevel.Information,
1,
"Executing RedirectToRouteResult, redirecting to {Destination} from route {RouteName}.");
_redirectToPageResultExecuting = LoggerMessage.Define<string>(
LogLevel.Information,
1,
"Executing RedirectToPageResult, redirecting to {Page}.");
_noActionsMatched = LoggerMessage.Define<string[]>(
LogLevel.Debug,
3,
"No actions matched the current request. Route values: {RouteValues}");
_featureNotFound = LoggerMessage.Define(
LogLevel.Warning,
1,
"A request body size limit could not be applied. This server does not support the IHttpRequestBodySizeFeature.");
_featureIsReadOnly = LoggerMessage.Define(
LogLevel.Warning,
2,
"A request body size limit could not be applied. The IHttpRequestBodySizeFeature for the server is read-only.");
_maxRequestBodySizeSet = LoggerMessage.Define<string>(
LogLevel.Debug,
3,
"The maximum request body size has been set to {RequestSize}.");
_requestBodySizeLimitDisabled = LoggerMessage.Define(
LogLevel.Debug,
3,
"The request body size limit has been disabled.");
_cannotApplyRequestFormLimits = LoggerMessage.Define(
LogLevel.Warning,
1,
"Unable to apply configured form options since the request form has already been read.");
_appliedRequestFormLimits = LoggerMessage.Define(
LogLevel.Debug,
2,
"Applied the configured form options on the current request.");
_modelStateInvalidFilterExecuting = LoggerMessage.Define(
LogLevel.Debug,
1,
"The request has model state errors, returning an error response.");
_inferredParameterSource = LoggerMessage.Define<MethodInfo, string, string>(
LogLevel.Debug,
1,
"Inferred binding source for '{ParameterName}` on `{ActionName}` as {BindingSource}.");
_unsupportedFormatFilterContentType = LoggerMessage.Define<string>(
LogLevel.Debug,
1,
"Could not find a media type for the format '{FormatFilterContentType}'.");
_actionDoesNotSupportFormatFilterContentType = LoggerMessage.Define<string, MediaTypeCollection>(
LogLevel.Debug,
2,
"Current action does not support the content type '{FormatFilterContentType}'. The supported content types are '{SupportedMediaTypes}'.");
_cannotApplyFormatFilterContentType = LoggerMessage.Define<string>(
LogLevel.Debug,
3,
"Cannot apply content type '{FormatFilterContentType}' to the response as current action had explicitly set a preferred content type.");
_notMostEffectiveFilter = LoggerMessage.Define<Type, Type, Type>(
LogLevel.Debug,
4,
"Execution of filter {OverriddenFilter} is preempted by filter {OverridingFilter} which is the most effective filter implementing policy {FilterPolicy}.");
_actionDoesNotExplicitlySpecifyContentTypes = LoggerMessage.Define(
LogLevel.Debug,
5,
"Current action does not explicitly specify any content types for the response.");
_selectingOutputFormatterUsingAcceptHeader = LoggerMessage.Define<IEnumerable<MediaTypeSegmentWithQuality>>(
LogLevel.Debug,
6,
"Attempting to select an output formatter based on Accept header '{AcceptHeader}'.");
_selectingOutputFormatterUsingAcceptHeaderAndExplicitContentTypes = LoggerMessage.Define<IEnumerable<MediaTypeSegmentWithQuality>, MediaTypeCollection>(
LogLevel.Debug,
7,
"Attempting to select an output formatter based on Accept header '{AcceptHeader}' and explicitly specified content types '{ExplicitContentTypes}'. The content types in the accept header must be a subset of the explicitly set content types.");
_selectingOutputFormatterWithoutUsingContentTypes = LoggerMessage.Define(
LogLevel.Debug,
8,
"Attempting to select an output formatter without using a content type as no explicit content types were specified for the response.");
_selectingOutputFormatterUsingContentTypes = LoggerMessage.Define<MediaTypeCollection>(
LogLevel.Debug,
9,
"Attempting to select the first output formatter in the output formatters list which supports a content type from the explicitly specified content types '{ExplicitContentTypes}'.");
_selectingFirstCanWriteFormatter = LoggerMessage.Define(
LogLevel.Debug,
10,
"Attempting to select the first formatter in the output formatters list which can write the result.");
_registeredOutputFormatters = LoggerMessage.Define<IEnumerable<IOutputFormatter>>(
LogLevel.Debug,
11,
"List of registered output formatters, in the following order: {OutputFormatters}");
_writingRangeToBody = LoggerMessage.Define(
LogLevel.Debug,
17,
"Writing the requested range of bytes to the body...");
_registeredModelBinderProviders = LoggerMessage.Define<IModelBinderProvider[]>(
LogLevel.Debug,
12,
"Registered model binder providers, in the following order: {ModelBinderProviders}");
_attemptingToBindPropertyModel = LoggerMessage.Define<Type, string, Type, string>(
LogLevel.Debug,
13,
"Attempting to bind property '{PropertyContainerType}.{PropertyName}' of type '{ModelType}' using the name '{ModelName}' in request data ...");
_doneAttemptingToBindPropertyModel = LoggerMessage.Define<Type, string, Type>(
LogLevel.Debug,
14,
"Done attempting to bind property '{PropertyContainerType}.{PropertyName}' of type '{ModelType}'.");
_foundNoValueForPropertyInRequest = LoggerMessage.Define<string, Type, string, Type>(
LogLevel.Debug,
15,
"Could not find a value in the request with name '{ModelName}' for binding property '{PropertyContainerType}.{ModelFieldName}' of type '{ModelType}'.");
_foundNoValueForParameterInRequest = LoggerMessage.Define<string, string, Type>(
LogLevel.Debug,
16,
"Could not find a value in the request with name '{ModelName}' for binding parameter '{ModelFieldName}' of type '{ModelType}'.");
_noPublicSettableProperties = LoggerMessage.Define<string, Type>(
LogLevel.Debug,
17,
"Could not bind to model with name '{ModelName}' and type '{ModelType}' as the type has no public settable properties.");
_cannotBindToComplexType = LoggerMessage.Define<Type>(
LogLevel.Debug,
18,
"Could not bind to model of type '{ModelType}' as there were no values in the request for any of the properties.");
_cannotBindToFilesCollectionDueToUnsupportedContentType = LoggerMessage.Define<string, Type>(
LogLevel.Debug,
19,
"Could not bind to model with name '{ModelName}' and type '{ModelType}' as the request did not have a content type of either 'application/x-www-form-urlencoded' or 'multipart/form-data'.");
_cannotCreateHeaderModelBinder = LoggerMessage.Define<Type>(
LogLevel.Debug,
20,
"Could not create a binder for type '{ModelType}' as this binder only supports simple types (like string, int, bool, enum) or a collection of simple types.");
_noFilesFoundInRequest = LoggerMessage.Define(
LogLevel.Debug,
21,
"No files found in the request to bind the model to.");
_attemptingToBindParameter = LoggerMessage.Define<string, Type>(
LogLevel.Debug,
22,
"Attempting to bind parameter '{ParameterName}' of type '{ModelType}' ...");
_doneAttemptingToBindParameter = LoggerMessage.Define<string, Type>(
LogLevel.Debug,
23,
"Done attempting to bind parameter '{ParameterName}' of type '{ModelType}'.");
_attemptingToBindModel = LoggerMessage.Define<Type, string>(
LogLevel.Debug,
24,
"Attempting to bind model of type '{ModelType}' using the name '{ModelName}' in request data ...");
_doneAttemptingToBindModel = LoggerMessage.Define<Type, string>(
LogLevel.Debug,
25,
"Done attempting to bind model of type '{ModelType}' using the name '{ModelName}'.");
_attemptingToValidateParameter = LoggerMessage.Define<string, Type>(
LogLevel.Debug,
26,
"Attempting to validate the bound parameter '{ParameterName}' of type '{ModelType}' ...");
_doneAttemptingToValidateParameter = LoggerMessage.Define<string, Type>(
LogLevel.Debug,
27,
"Done attempting to validate the bound parameter '{ParameterName}' of type '{ModelType}'.");
_noNonIndexBasedFormatFoundForCollection = LoggerMessage.Define<string, string>(
LogLevel.Debug,
28,
"Could not bind to collection using a format like {ModelName}=value1&{ModelName}=value2");
_attemptingToBindCollectionUsingIndices = LoggerMessage.Define<string, string, string, string, string, string>(
LogLevel.Debug,
29,
"Attempting to bind model using indices. Example formats include: " +
"[0]=value1&[1]=value2, " +
"{ModelName}[0]=value1&{ModelName}[1]=value2, " +
"{ModelName}.index=zero&{ModelName}.index=one&{ModelName}[zero]=value1&{ModelName}[one]=value2");
_attemptingToBindCollectionOfKeyValuePair = LoggerMessage.Define<string, string, string, string, string, string>(
LogLevel.Debug,
30,
"Attempting to bind collection of KeyValuePair. Example formats include: " +
"[0].Key=key1&[0].Value=value1&[1].Key=key2&[1].Value=value2, " +
"{ModelName}[0].Key=key1&{ModelName}[0].Value=value1&{ModelName}[1].Key=key2&{ModelName}[1].Value=value2, " +
"{ModelName}[key1]=value1&{ModelName}[key2]=value2");
_noKeyValueFormatForDictionaryModelBinder = LoggerMessage.Define<string, string, string>(
LogLevel.Debug,
33,
"Attempting to bind model with name '{ModelName}' using the format {ModelName}[key1]=value1&{ModelName}[key2]=value2");
_ifMatchPreconditionFailed = LoggerMessage.Define<EntityTagHeaderValue>(
LogLevel.Debug,
34,
"Current request's If-Match header check failed as the file's current etag '{CurrentETag}' does not match with any of the supplied etags.");
_ifUnmodifiedSincePreconditionFailed = LoggerMessage.Define<DateTimeOffset?, DateTimeOffset?>(
LogLevel.Debug,
35,
"Current request's If-Unmodified-Since header check failed as the file was modified (at '{lastModified}') after the If-Unmodified-Since date '{IfUnmodifiedSinceDate}'.");
_ifRangeLastModifiedPreconditionFailed = LoggerMessage.Define<DateTimeOffset?, DateTimeOffset?>(
LogLevel.Debug,
36,
"Could not serve range as the file was modified (at {LastModified}) after the if-Range's last modified date '{IfRangeLastModified}'.");
_ifRangeETagPreconditionFailed = LoggerMessage.Define<EntityTagHeaderValue, EntityTagHeaderValue>(
LogLevel.Debug,
37,
"Could not serve range as the file's current etag '{CurrentETag}' does not match the If-Range etag '{IfRangeETag}'.");
_notEnabledForRangeProcessing = LoggerMessage.Define(
LogLevel.Debug,
38,
$"The file result has not been enabled for processing range requests. To enable it, set the property '{nameof(FileResult.EnableRangeProcessing)}' on the result to 'true'.");
_attemptingToBindProperty = LoggerMessage.Define<Type, string, Type>(
LogLevel.Debug,
39,
"Attempting to bind property '{PropertyContainerType}.{PropertyName}' of type '{ModelType}' ...");
_doneAttemptingToBindProperty = LoggerMessage.Define<Type, string, Type>(
LogLevel.Debug,
40,
"Done attempting to bind property '{PropertyContainerType}.{PropertyName}' of type '{ModelType}'.");
_attemptingToValidateProperty = LoggerMessage.Define<Type, string, Type>(
LogLevel.Debug,
41,
"Attempting to validate the bound property '{PropertyContainerType}.{PropertyName}' of type '{ModelType}' ...");
_doneAttemptingToValidateProperty = LoggerMessage.Define<Type, string, Type>(
LogLevel.Debug,
42,
"Done attempting to validate the bound property '{PropertyContainerType}.{PropertyName}' of type '{ModelType}'.");
_cannotCreateHeaderModelBinderCompatVersion_2_0 = LoggerMessage.Define<Type>(
LogLevel.Debug,
43,
"Could not create a binder for type '{ModelType}' as this binder only supports 'System.String' type or a collection of 'System.String'.");
_attemptingToBindParameterModel = LoggerMessage.Define<string, Type, string>(
LogLevel.Debug,
44,
"Attempting to bind parameter '{ParameterName}' of type '{ModelType}' using the name '{ModelName}' in request data ...");
_doneAttemptingToBindParameterModel = LoggerMessage.Define<string, Type>(
LogLevel.Debug,
45,
"Done attempting to bind parameter '{ParameterName}' of type '{ModelType}'.");
_foundNoValueInRequest = LoggerMessage.Define<string, Type>(
LogLevel.Debug,
46,
"Could not find a value in the request with name '{ModelName}' of type '{ModelType}'.");
_parameterBinderRequestPredicateShortCircuitOfProperty = LoggerMessage.Define<Type, string>(
LogLevel.Debug,
47,
"Skipped binding property '{PropertyContainerType}.{PropertyName}' since its binding information disallowed it for the current request.");
_parameterBinderRequestPredicateShortCircuitOfParameter = LoggerMessage.Define<string>(
LogLevel.Debug,
48,
"Skipped binding parameter '{ParameterName}' since its binding information disallowed it for the current request.");
_transformingClientError = LoggerMessage.Define<Type, int?, Type>(
LogLevel.Trace,
new EventId(49, nameof(Infrastructure.ClientErrorResultFilter)),
"Replacing {InitialActionResultType} with status code {StatusCode} with {ReplacedActionResultType}.");
}
public static void RegisteredOutputFormatters(this ILogger logger, IEnumerable<IOutputFormatter> outputFormatters)
{
_registeredOutputFormatters(logger, outputFormatters, null);
}
public static void SelectingOutputFormatterUsingAcceptHeaderAndExplicitContentTypes(
this ILogger logger,
IEnumerable<MediaTypeSegmentWithQuality> acceptHeader,
MediaTypeCollection mediaTypeCollection)
{
_selectingOutputFormatterUsingAcceptHeaderAndExplicitContentTypes(logger, acceptHeader, mediaTypeCollection, null);
}
public static void SelectingOutputFormatterUsingAcceptHeader(this ILogger logger, IEnumerable<MediaTypeSegmentWithQuality> acceptHeader)
{
_selectingOutputFormatterUsingAcceptHeader(logger, acceptHeader, null);
}
public static void SelectingOutputFormatterUsingContentTypes(this ILogger logger, MediaTypeCollection mediaTypeCollection)
{
_selectingOutputFormatterUsingContentTypes(logger, mediaTypeCollection, null);
}
public static void SelectingOutputFormatterWithoutUsingContentTypes(this ILogger logger)
{
_selectingOutputFormatterWithoutUsingContentTypes(logger, null);
}
public static void SelectFirstCanWriteFormatter(this ILogger logger)
{
_selectingFirstCanWriteFormatter(logger, null);
}
public static IDisposable ActionScope(this ILogger logger, ActionDescriptor action)
{
return logger.BeginScope(new ActionLogScope(action));
}
public static void ExecutingAction(this ILogger logger, ActionDescriptor action)
{
if (logger.IsEnabled(LogLevel.Information))
{
var routeKeys = action.RouteValues.Keys.ToArray();
var routeValues = action.RouteValues.Values.ToArray();
var stringBuilder = new StringBuilder();
stringBuilder.Append("{");
for (var i = 0; i < routeValues.Length; i++)
{
if (i == routeValues.Length - 1)
{
stringBuilder.Append($"{routeKeys[i]} = \"{routeValues[i]}\"}}");
}
else
{
stringBuilder.Append($"{routeKeys[i]} = \"{routeValues[i]}\", ");
}
}
if (action.RouteValues.TryGetValue("page", out var page) && page != null)
{
_pageExecuting(logger, stringBuilder.ToString(), action.DisplayName, null);
}
else
{
_actionExecuting(logger, stringBuilder.ToString(), action.DisplayName, null);
}
}
}
public static void AuthorizationFiltersExecutionPlan(this ILogger logger, IEnumerable<IFilterMetadata> filters)
{
if (!logger.IsEnabled(LogLevel.Debug))
{
return;
}
var authorizationFilters = filters.Where(f => f is IAuthorizationFilter || f is IAsyncAuthorizationFilter);
LogFilterExecutionPlan(logger, "authorization", authorizationFilters);
}
public static void ResourceFiltersExecutionPlan(this ILogger logger, IEnumerable<IFilterMetadata> filters)
{
if (!logger.IsEnabled(LogLevel.Debug))
{
return;
}
var resourceFilters = filters.Where(f => f is IResourceFilter || f is IAsyncResourceFilter);
LogFilterExecutionPlan(logger, "resource", resourceFilters);
}
public static void ActionFiltersExecutionPlan(this ILogger logger, IEnumerable<IFilterMetadata> filters)
{
if (!logger.IsEnabled(LogLevel.Debug))
{
return;
}
var actionFilters = filters.Where(f => f is IActionFilter || f is IAsyncActionFilter);
LogFilterExecutionPlan(logger, "action", actionFilters);
}
public static void ExceptionFiltersExecutionPlan(this ILogger logger, IEnumerable<IFilterMetadata> filters)
{
if (!logger.IsEnabled(LogLevel.Debug))
{
return;
}
var exceptionFilters = filters.Where(f => f is IExceptionFilter || f is IAsyncExceptionFilter);
LogFilterExecutionPlan(logger, "exception", exceptionFilters);
}
public static void ResultFiltersExecutionPlan(this ILogger logger, IEnumerable<IFilterMetadata> filters)
{
if (!logger.IsEnabled(LogLevel.Debug))
{
return;
}
var resultFilters = filters.Where(f => f is IResultFilter || f is IAsyncResultFilter);
LogFilterExecutionPlan(logger, "result", resultFilters);
}
public static void BeforeExecutingMethodOnFilter(
this ILogger logger,
string filterType,
string methodName,
IFilterMetadata filter)
{
_beforeExecutingMethodOnFilter(logger, filterType, methodName, filter.GetType(), null);
}
public static void AfterExecutingMethodOnFilter(
this ILogger logger,
string filterType,
string methodName,
IFilterMetadata filter)
{
_afterExecutingMethodOnFilter(logger, filterType, methodName, filter.GetType(), null);
}
public static void ExecutedAction(this ILogger logger, ActionDescriptor action, TimeSpan timeSpan)
{
// Don't log if logging wasn't enabled at start of request as time will be wildly wrong.
if (logger.IsEnabled(LogLevel.Information))
{
if (action.RouteValues.TryGetValue("page", out var page) && page != null)
{
_pageExecuted(logger, action.DisplayName, timeSpan.TotalMilliseconds, null);
}
else
{
_actionExecuted(logger, action.DisplayName, timeSpan.TotalMilliseconds, null);
}
}
}
public static void NoActionsMatched(this ILogger logger, IDictionary<string, object> routeValueDictionary)
{
if (logger.IsEnabled(LogLevel.Debug))
{
string[] routeValues = null;
if (routeValueDictionary != null)
{
routeValues = routeValueDictionary
.Select(pair => pair.Key + "=" + Convert.ToString(pair.Value))
.ToArray();
}
_noActionsMatched(logger, routeValues, null);
}
}
public static void ChallengeResultExecuting(this ILogger logger, IList<string> schemes)
{
if (logger.IsEnabled(LogLevel.Information))
{
_challengeResultExecuting(logger, schemes.ToArray(), null);
}
}
public static void ContentResultExecuting(this ILogger logger, string contentType)
{
_contentResultExecuting(logger, contentType, null);
}
public static void BeforeExecutingActionResult(this ILogger logger, IActionResult actionResult)
{
_beforeExecutingActionResult(logger, actionResult.GetType(), null);
}
public static void AfterExecutingActionResult(this ILogger logger, IActionResult actionResult)
{
_afterExecutingActionResult(logger, actionResult.GetType(), null);
}
public static void ActionMethodExecuting(this ILogger logger, ControllerContext context, object[] arguments)
{
if (logger.IsEnabled(LogLevel.Information))
{
var actionName = context.ActionDescriptor.DisplayName;
var validationState = context.ModelState.ValidationState;
string[] convertedArguments;
if (arguments == null)
{
_actionMethodExecuting(logger, actionName, validationState, null);
}
else
{
convertedArguments = new string[arguments.Length];
for (var i = 0; i < arguments.Length; i++)
{
convertedArguments[i] = Convert.ToString(arguments[i]);
}
_actionMethodExecutingWithArguments(logger, actionName, convertedArguments, validationState, null);
}
}
}
public static void ActionMethodExecuted(this ILogger logger, ControllerContext context, IActionResult result, TimeSpan timeSpan)
{
if (logger.IsEnabled(LogLevel.Information))
{
var actionName = context.ActionDescriptor.DisplayName;
_actionMethodExecuted(logger, actionName, Convert.ToString(result), timeSpan.TotalMilliseconds, null);
}
}
public static void AmbiguousActions(this ILogger logger, string actionNames)
{
_ambiguousActions(logger, actionNames, null);
}
public static void ConstraintMismatch(
this ILogger logger,
string actionName,
string actionId,
IActionConstraint actionConstraint)
{
_constraintMismatch(logger, actionName, actionId, actionConstraint, null);
}
public static void ExecutingFileResult(this ILogger logger, FileResult fileResult)
{
_executingFileResultWithNoFileName(logger, fileResult, fileResult.FileDownloadName, null);
}
public static void ExecutingFileResult(this ILogger logger, FileResult fileResult, string fileName)
{
_executingFileResult(logger, fileResult, fileName, fileResult.FileDownloadName, null);
}
public static void NotEnabledForRangeProcessing(this ILogger logger)
{
_notEnabledForRangeProcessing(logger, null);
}
public static void WritingRangeToBody(this ILogger logger)
{
_writingRangeToBody(logger, null);
}
public static void AuthorizationFailure(
this ILogger logger,
IFilterMetadata filter)
{
_authorizationFailure(logger, filter, null);
}
public static void ResourceFilterShortCircuited(
this ILogger logger,
IFilterMetadata filter)
{
_resourceFilterShortCircuit(logger, filter, null);
}
public static void ResultFilterShortCircuited(
this ILogger logger,
IFilterMetadata filter)
{
_resultFilterShortCircuit(logger, filter, null);
}
public static void ExceptionFilterShortCircuited(
this ILogger logger,
IFilterMetadata filter)
{
_exceptionFilterShortCircuit(logger, filter, null);
}
public static void ActionFilterShortCircuited(
this ILogger logger,
IFilterMetadata filter)
{
_actionFilterShortCircuit(logger, filter, null);
}
public static void ForbidResultExecuting(this ILogger logger, IList<string> authenticationSchemes)
{
if (logger.IsEnabled(LogLevel.Information))
{
_forbidResultExecuting(logger, authenticationSchemes.ToArray(), null);
}
}
public static void SignInResultExecuting(this ILogger logger, string authenticationScheme, ClaimsPrincipal principal)
{
_signInResultExecuting(logger, authenticationScheme, principal, null);
}
public static void SignOutResultExecuting(this ILogger logger, IList<string> authenticationSchemes)
{
if (logger.IsEnabled(LogLevel.Information))
{
_signOutResultExecuting(logger, authenticationSchemes.ToArray(), null);
}
}
public static void HttpStatusCodeResultExecuting(this ILogger logger, int statusCode)
{
_httpStatusCodeResultExecuting(logger, statusCode, null);
}
public static void LocalRedirectResultExecuting(this ILogger logger, string destination)
{
_localRedirectResultExecuting(logger, destination, null);
}
public static void ObjectResultExecuting(this ILogger logger, object value)
{
if (logger.IsEnabled(LogLevel.Information))
{
var type = value == null ? "null" : value.GetType().FullName;
_objectResultExecuting(logger, type, null);
}
}
public static void NoFormatter(
this ILogger logger,