@@ -11,6 +11,115 @@ namespace Microsoft.Extensions.Logging;
1111// ---------------------------------------------------------------------------------------------------------------------
1212public static class LoggerExtensions {
1313
14+ #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 ) {
24+ logger . Information ( messageTemplate , propertyValues ) ;
25+ return false ;
26+ }
27+
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 ) {
37+ logger . Debug ( messageTemplate , propertyValues ) ;
38+ return false ;
39+ }
40+
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 ) {
50+ logger . Warning ( messageTemplate , propertyValues ) ;
51+ return false ;
52+ }
53+
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 ) {
64+ logger . Error ( messageTemplate , propertyValues ) ;
65+ return false ;
66+ }
67+
68+ #endregion
69+ #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 ) {
79+ logger . LogDebug ( messageTemplate , propertyValues ) ;
80+ return true ;
81+ }
82+
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 ) {
92+ logger . LogInformation ( messageTemplate , propertyValues ) ;
93+ return true ;
94+ }
95+
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 ) {
105+ logger . LogWarning ( messageTemplate , propertyValues ) ;
106+ return true ;
107+ }
108+
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 ) {
118+ logger . LogError ( messageTemplate , propertyValues ) ;
119+ return true ;
120+ }
121+ #endregion
122+
14123 [ StringFormatMethod ( "message" ) ]
15124 public static void Debug ( this ILogger logger , EventId eventId , Exception ? exception , string ? message , params object ? [ ] args )
16125 => logger . LogDebug ( eventId , exception , message , args ) ;
0 commit comments