@@ -44,13 +44,15 @@ static MvcViewFeaturesLoggerExtensions()
44
44
_viewComponentExecuting = LoggerMessage . Define < string , string [ ] > (
45
45
LogLevel . Debug ,
46
46
new EventId ( 1 , "ViewComponentExecuting" ) ,
47
- "Executing view component {ViewComponentName} with arguments ({Arguments})." ) ;
47
+ "Executing view component {ViewComponentName} with arguments ({Arguments})." ,
48
+ skipEnabledCheck : true ) ;
48
49
49
50
_viewComponentExecuted = LoggerMessage . Define < string , double , string > (
50
51
LogLevel . Debug ,
51
52
new EventId ( 2 , "ViewComponentExecuted" ) ,
52
53
"Executed view component {ViewComponentName} in {ElapsedMilliseconds}ms and returned " +
53
- "{ViewComponentResult}" ) ;
54
+ "{ViewComponentResult}" ,
55
+ skipEnabledCheck : true ) ;
54
56
55
57
_partialViewResultExecuting = LoggerMessage . Define < string > (
56
58
LogLevel . Information ,
@@ -136,8 +138,11 @@ public static void ViewComponentExecuting(
136
138
ViewComponentContext context ,
137
139
object [ ] arguments )
138
140
{
139
- var formattedArguments = GetFormattedArguments ( arguments ) ;
140
- _viewComponentExecuting ( logger , context . ViewComponentDescriptor . DisplayName , formattedArguments , null ) ;
141
+ if ( logger . IsEnabled ( LogLevel . Debug ) )
142
+ {
143
+ var formattedArguments = GetFormattedArguments ( arguments ) ;
144
+ _viewComponentExecuting ( logger , context . ViewComponentDescriptor . DisplayName , formattedArguments , null ) ;
145
+ }
141
146
}
142
147
143
148
private static string [ ] GetFormattedArguments ( object [ ] arguments )
@@ -163,12 +168,15 @@ public static void ViewComponentExecuted(
163
168
object result )
164
169
{
165
170
// Don't log if logging wasn't enabled at start of request as time will be wildly wrong.
166
- _viewComponentExecuted (
167
- logger ,
168
- context . ViewComponentDescriptor . DisplayName ,
169
- timespan . TotalMilliseconds ,
170
- Convert . ToString ( result , CultureInfo . InvariantCulture ) ,
171
- null ) ;
171
+ if ( logger . IsEnabled ( LogLevel . Debug ) )
172
+ {
173
+ _viewComponentExecuted (
174
+ logger ,
175
+ context . ViewComponentDescriptor . DisplayName ,
176
+ timespan . TotalMilliseconds ,
177
+ Convert . ToString ( result , CultureInfo . InvariantCulture ) ,
178
+ null ) ;
179
+ }
172
180
}
173
181
174
182
public static void PartialViewFound (
0 commit comments