@@ -9,210 +9,123 @@ namespace Microsoft.Extensions.Logging;
99// ---------------------------------------------------------------------------------------------------------------------
1010// Code
1111// ---------------------------------------------------------------------------------------------------------------------
12+
13+ #pragma warning disable CA2254
1214public static class LoggerExtensions {
13-
1415 #region AsFalse
15- /// <summary>
16- /// Logs an informational message and returns false.
17- /// </summary>
18- /// <param name="logger">The logger instance.</param>
19- /// <param name="messageTemplate">The message template to log.</param>
20- /// <param name="propertyValues">The property values for the message template.</param>
21- /// <returns>Always returns false.</returns>
22- [ StringFormatMethod ( "messageTemplate" ) ]
23- public static bool InformationAsFalse ( this ILogger logger , string messageTemplate , params object ? [ ] propertyValues ) {
16+ public static bool InformationAsFalse ( this ILogger logger , [ StructuredMessageTemplate ] string messageTemplate , params object ? [ ] propertyValues ) {
2417 logger . Information ( messageTemplate , propertyValues ) ;
2518 return false ;
2619 }
2720
28- /// <summary>
29- /// Logs a debug-level message and always returns false.
30- /// </summary>
31- /// <param name="logger">The logger instance used to log the message.</param>
32- /// <param name="messageTemplate">The message template that describes the log message.</param>
33- /// <param name="propertyValues">Optional property values for formatting the message template.</param>
34- /// <returns>Always returns false.</returns>
35- [ StringFormatMethod ( "messageTemplate" ) ]
36- public static bool DebugAsFalse ( this ILogger logger , string messageTemplate , params object ? [ ] propertyValues ) {
21+ public static bool DebugAsFalse ( this ILogger logger , [ StructuredMessageTemplate ] string messageTemplate , params object ? [ ] propertyValues ) {
3722 logger . Debug ( messageTemplate , propertyValues ) ;
3823 return false ;
3924 }
4025
41- /// <summary>
42- /// Logs a warning message and always returns false.
43- /// </summary>
44- /// <param name="logger">The logger instance.</param>
45- /// <param name="messageTemplate">The message template to log.</param>
46- /// <param name="propertyValues">Values to format into the template.</param>
47- /// <returns>Always returns false.</returns>
48- [ StringFormatMethod ( "messageTemplate" ) ]
49- public static bool WarningAsFalse ( this ILogger logger , string messageTemplate , params object ? [ ] propertyValues ) {
26+ public static bool WarningAsFalse ( this ILogger logger , [ StructuredMessageTemplate ] string messageTemplate , params object ? [ ] propertyValues ) {
5027 logger . Warning ( messageTemplate , propertyValues ) ;
5128 return false ;
5229 }
5330
54- /// <summary>
55- /// Logs an error message with the specified message template and property values,
56- /// then always returns false.
57- /// </summary>
58- /// <param name="logger">The logger instance.</param>
59- /// <param name="messageTemplate">The message template describing the log message format.</param>
60- /// <param name="propertyValues">An array of objects to format into the message template.</param>
61- /// <returns>Always returns false.</returns>
62- [ StringFormatMethod ( "messageTemplate" ) ]
63- public static bool ErrorAsFalse ( this ILogger logger , string messageTemplate , params object ? [ ] propertyValues ) {
31+ public static bool ErrorAsFalse ( this ILogger logger , [ StructuredMessageTemplate ] string messageTemplate , params object ? [ ] propertyValues ) {
6432 logger . Error ( messageTemplate , propertyValues ) ;
6533 return false ;
6634 }
6735
6836 #endregion
6937 #region AsTrue
70- /// <summary>
71- /// Logs a debug-level message and returns true.
72- /// </summary>
73- /// <param name="logger">The logger instance.</param>
74- /// <param name="messageTemplate">The message template for the log entry.</param>
75- /// <param name="propertyValues">The property values corresponding to the message template.</param>
76- /// <returns>Always returns true.</returns>
77- [ StringFormatMethod ( "messageTemplate" ) ]
78- public static bool DebugAsTrue ( this ILogger logger , string messageTemplate , params object ? [ ] propertyValues ) {
38+ public static bool DebugAsTrue ( this ILogger logger , [ StructuredMessageTemplate ] string messageTemplate , params object ? [ ] propertyValues ) {
7939 logger . LogDebug ( messageTemplate , propertyValues ) ;
8040 return true ;
8141 }
8242
83- /// <summary>
84- /// Logs an information-level message and returns true.
85- /// </summary>
86- /// <param name="logger">The logger instance.</param>
87- /// <param name="messageTemplate">The message template to log.</param>
88- /// <param name="propertyValues">An array of property values to format and include in the message.</param>
89- /// <returns>Returns true after logging the message.</returns>
90- [ StringFormatMethod ( "messageTemplate" ) ]
91- public static bool InformationAsTrue ( this ILogger logger , string messageTemplate , params object ? [ ] propertyValues ) {
43+ public static bool InformationAsTrue ( this ILogger logger , [ StructuredMessageTemplate ] string messageTemplate , params object ? [ ] propertyValues ) {
9244 logger . LogInformation ( messageTemplate , propertyValues ) ;
9345 return true ;
9446 }
9547
96- /// <summary>
97- /// Logs a warning level message and returns true.
98- /// </summary>
99- /// <param name="logger">The logger instance used for logging.</param>
100- /// <param name="messageTemplate">The message template describing the log event.</param>
101- /// <param name="propertyValues">The values to format the message template.</param>
102- /// <returns>Always returns true.</returns>
103- [ StringFormatMethod ( "messageTemplate" ) ]
104- public static bool WarningAsTrue ( this ILogger logger , string messageTemplate , params object ? [ ] propertyValues ) {
48+ public static bool WarningAsTrue ( this ILogger logger , [ StructuredMessageTemplate ] string messageTemplate , params object ? [ ] propertyValues ) {
10549 logger . LogWarning ( messageTemplate , propertyValues ) ;
10650 return true ;
10751 }
10852
109- /// <summary>
110- /// Logs an error message at the Error level and returns a boolean value of true.
111- /// </summary>
112- /// <param name="logger">The logger instance.</param>
113- /// <param name="messageTemplate">The message template to be logged.</param>
114- /// <param name="propertyValues">The property values for the message template.</param>
115- /// <returns>True, indicating that the operation was successful.</returns>
116- [ StringFormatMethod ( "messageTemplate" ) ]
117- public static bool ErrorAsTrue ( this ILogger logger , string messageTemplate , params object ? [ ] propertyValues ) {
53+ public static bool ErrorAsTrue ( this ILogger logger , [ StructuredMessageTemplate ] string messageTemplate , params object ? [ ] propertyValues ) {
11854 logger . LogError ( messageTemplate , propertyValues ) ;
11955 return true ;
12056 }
12157 #endregion
122-
123- [ StringFormatMethod ( "message" ) ]
124- public static void Debug ( this ILogger logger , EventId eventId , Exception ? exception , string ? message , params object ? [ ] args )
58+
59+ public static void Debug ( this ILogger logger , EventId eventId , Exception ? exception , [ StructuredMessageTemplate ] string message , params object ? [ ] args )
12560 => logger . LogDebug ( eventId , exception , message , args ) ;
126-
127- [ StringFormatMethod ( "message" ) ]
128- public static void Debug ( this ILogger logger , EventId eventId , string ? message , params object ? [ ] args )
61+
62+ public static void Debug ( this ILogger logger , EventId eventId , [ StructuredMessageTemplate ] string message , params object ? [ ] args )
12963 => logger . LogDebug ( eventId , message , args ) ;
130-
131- [ StringFormatMethod ( "message" ) ]
132- public static void Debug ( this ILogger logger , Exception ? exception , string ? message , params object ? [ ] args )
64+
65+ public static void Debug ( this ILogger logger , Exception ? exception , [ StructuredMessageTemplate ] string message , params object ? [ ] args )
13366 => logger . LogDebug ( exception , message , args ) ;
134-
135- [ StringFormatMethod ( "message" ) ]
136- public static void Debug ( this ILogger logger , string ? message , params object ? [ ] args )
67+
68+ public static void Debug ( this ILogger logger , [ StructuredMessageTemplate ] string message , params object ? [ ] args )
13769 => logger . LogDebug ( message , args ) ;
138-
139- [ StringFormatMethod ( "message" ) ]
140- public static void Trace ( this ILogger logger , EventId eventId , Exception ? exception , string ? message , params object ? [ ] args )
70+
71+ public static void Trace ( this ILogger logger , EventId eventId , Exception ? exception , [ StructuredMessageTemplate ] string message , params object ? [ ] args )
14172 => logger . LogTrace ( eventId , exception , message , args ) ;
142-
143- [ StringFormatMethod ( "message" ) ]
144- public static void Trace ( this ILogger logger , EventId eventId , string ? message , params object ? [ ] args )
73+
74+ public static void Trace ( this ILogger logger , EventId eventId , [ StructuredMessageTemplate ] string message , params object ? [ ] args )
14575 => logger . LogTrace ( eventId , message , args ) ;
146-
147- [ StringFormatMethod ( "message" ) ]
148- public static void Trace ( this ILogger logger , Exception ? exception , string ? message , params object ? [ ] args )
76+
77+ public static void Trace ( this ILogger logger , Exception ? exception , [ StructuredMessageTemplate ] string message , params object ? [ ] args )
14978 => logger . LogTrace ( exception , message , args ) ;
150-
151- [ StringFormatMethod ( "message" ) ]
152- public static void Trace ( this ILogger logger , string ? message , params object ? [ ] args )
79+
80+ public static void Trace ( this ILogger logger , [ StructuredMessageTemplate ] string message , params object ? [ ] args )
15381 => logger . LogTrace ( message , args ) ;
154-
155- [ StringFormatMethod ( "message" ) ]
156- public static void Information ( this ILogger logger , EventId eventId , Exception ? exception , string ? message , params object ? [ ] args )
82+
83+ public static void Information ( this ILogger logger , EventId eventId , Exception ? exception , [ StructuredMessageTemplate ] string message , params object ? [ ] args )
15784 => logger . LogInformation ( eventId , exception , message , args ) ;
158-
159- [ StringFormatMethod ( "message" ) ]
160- public static void Information ( this ILogger logger , EventId eventId , string ? message , params object ? [ ] args )
85+
86+ public static void Information ( this ILogger logger , EventId eventId , [ StructuredMessageTemplate ] string message , params object ? [ ] args )
16187 => logger . LogInformation ( eventId , message , args ) ;
162-
163- [ StringFormatMethod ( "message" ) ]
164- public static void Information ( this ILogger logger , Exception ? exception , string ? message , params object ? [ ] args )
88+
89+ public static void Information ( this ILogger logger , Exception ? exception , [ StructuredMessageTemplate ] string message , params object ? [ ] args )
16590 => logger . LogInformation ( exception , message , args ) ;
166-
167- [ StringFormatMethod ( "message" ) ]
168- public static void Information ( this ILogger logger , string ? message , params object ? [ ] args )
91+
92+ public static void Information ( this ILogger logger , [ StructuredMessageTemplate ] string message , params object ? [ ] args )
16993 => logger . LogInformation ( message , args ) ;
170-
171- [ StringFormatMethod ( "message" ) ]
172- public static void Warning ( this ILogger logger , EventId eventId , Exception ? exception , string ? message , params object ? [ ] args )
94+
95+ public static void Warning ( this ILogger logger , EventId eventId , Exception ? exception , [ StructuredMessageTemplate ] string message , params object ? [ ] args )
17396 => logger . LogWarning ( eventId , exception , message , args ) ;
174-
175- [ StringFormatMethod ( "message" ) ]
176- public static void Warning ( this ILogger logger , EventId eventId , string ? message , params object ? [ ] args )
97+
98+ public static void Warning ( this ILogger logger , EventId eventId , [ StructuredMessageTemplate ] string message , params object ? [ ] args )
17799 => logger . LogWarning ( eventId , message , args ) ;
178-
179- [ StringFormatMethod ( "message" ) ]
180- public static void Warning ( this ILogger logger , Exception ? exception , string ? message , params object ? [ ] args )
100+
101+ public static void Warning ( this ILogger logger , Exception ? exception , [ StructuredMessageTemplate ] string message , params object ? [ ] args )
181102 => logger . LogWarning ( exception , message , args ) ;
182-
183- [ StringFormatMethod ( "message" ) ]
184- public static void Warning ( this ILogger logger , string ? message , params object ? [ ] args )
103+
104+ public static void Warning ( this ILogger logger , [ StructuredMessageTemplate ] string message , params object ? [ ] args )
185105 => logger . LogWarning ( message , args ) ;
186-
187- [ StringFormatMethod ( "message" ) ]
188- public static void Error ( this ILogger logger , EventId eventId , Exception ? exception , string ? message , params object ? [ ] args )
106+
107+ public static void Error ( this ILogger logger , EventId eventId , Exception ? exception , [ StructuredMessageTemplate ] string message , params object ? [ ] args )
189108 => logger . LogError ( eventId , exception , message , args ) ;
190-
191- [ StringFormatMethod ( "message" ) ]
192- public static void Error ( this ILogger logger , EventId eventId , string ? message , params object ? [ ] args )
109+
110+ public static void Error ( this ILogger logger , EventId eventId , [ StructuredMessageTemplate ] string message , params object ? [ ] args )
193111 => logger . LogError ( eventId , message , args ) ;
194-
195- [ StringFormatMethod ( "message" ) ]
196- public static void Error ( this ILogger logger , Exception ? exception , string ? message , params object ? [ ] args )
112+
113+ public static void Error ( this ILogger logger , Exception ? exception , [ StructuredMessageTemplate ] string message , params object ? [ ] args )
197114 => logger . LogError ( exception , message , args ) ;
198-
199- [ StringFormatMethod ( "message" ) ]
200- public static void Error ( this ILogger logger , string ? message , params object ? [ ] args )
115+
116+ public static void Error ( this ILogger logger , [ StructuredMessageTemplate ] string message , params object ? [ ] args )
201117 => logger . LogError ( message , args ) ;
202-
203- [ StringFormatMethod ( "message" ) ]
204- public static void Critical ( this ILogger logger , EventId eventId , Exception ? exception , string ? message , params object ? [ ] args )
118+
119+ public static void Critical ( this ILogger logger , EventId eventId , Exception ? exception , [ StructuredMessageTemplate ] string message , params object ? [ ] args )
205120 => logger . LogCritical ( eventId , exception , message , args ) ;
206-
207- [ StringFormatMethod ( "message" ) ]
208- public static void Critical ( this ILogger logger , EventId eventId , string ? message , params object ? [ ] args )
121+
122+ public static void Critical ( this ILogger logger , EventId eventId , [ StructuredMessageTemplate ] string message , params object ? [ ] args )
209123 => logger . LogCritical ( eventId , message , args ) ;
210-
211- [ StringFormatMethod ( "message" ) ]
212- public static void Critical ( this ILogger logger , Exception ? exception , string ? message , params object ? [ ] args )
124+
125+ public static void Critical ( this ILogger logger , Exception ? exception , [ StructuredMessageTemplate ] string message , params object ? [ ] args )
213126 => logger . LogCritical ( exception , message , args ) ;
214-
215- [ StringFormatMethod ( "message" ) ]
216- public static void Critical ( this ILogger logger , string ? message , params object ? [ ] args )
127+
128+ public static void Critical ( this ILogger logger , [ StructuredMessageTemplate ] string message , params object ? [ ] args )
217129 => logger . LogCritical ( message , args ) ;
218130}
131+ #pragma warning restore CA2254
0 commit comments