@@ -15,7 +15,7 @@ public class OperationResult
1515 private readonly List < IOperationError > _errors = new ( ) ;
1616 private readonly List < string > _successMessages = new ( ) ;
1717
18- private readonly ILogger ? _logger ;
18+ protected readonly ILogger ? _logger ;
1919
2020 /// <summary>
2121 /// Gets or sets a value indicating whether the operation is successful or not.
@@ -208,13 +208,13 @@ public static OperationResult FromError(string message, int? code = null, LogLev
208208 }
209209
210210 // TODO: this method needs completing.
211- private static LogLevel GetLogLevel ( LogLevel ? optionalLevel ) => optionalLevel ?? LogLevel . Error ;
211+ protected static LogLevel GetLogLevel ( LogLevel ? optionalLevel ) => optionalLevel ?? LogLevel . Error ;
212212
213213 /// <summary>
214214 /// Appends an <see cref="IOperationError"/> to the internal errors collection.
215215 /// </summary>
216216 /// <param name="error">An instance of <see cref="IOperationError"/> to add to the internal errors collection.</param>
217- private void AppendErrorInternal ( IOperationError error ) => this . _errors . Add ( error ) ;
217+ protected void AppendErrorInternal ( IOperationError error ) => this . _errors . Add ( error ) ;
218218}
219219
220220/// <summary>
@@ -234,19 +234,19 @@ public OperationResult()
234234 /// <summary>
235235 /// Initializes a new instance of the <see cref="OperationResult"/> class.
236236 /// </summary>
237- /// <param name="loggerService ">An instance of <see cref="ILoggerService"/>.</param>
237+ /// <param name="logger ">An instance of <see cref="ILoggerService"/>.</param>
238238 /// <remarks>If the operation is a get operation, an empty result must return a truthy Success value.</remarks>
239- public OperationResult ( ILogger loggerService ) : base ( loggerService )
239+ public OperationResult ( ILogger logger ) : base ( logger )
240240 {
241241 }
242242
243243 /// <summary>
244244 /// Initializes a new instance of the <see cref="OperationResult"/> class and sets the passed result object. Internally, this will set the Success result to True.
245245 /// </summary>
246246 /// <param name="resultObject">An initial failure message for the operation result. This will fail the success status.</param>
247- /// <param name="loggerService ">An instance of <see cref="ILoggerService "/>.</param>
247+ /// <param name="logger ">An instance of <see cref="ILogger "/>.</param>
248248 /// <remarks>If the operation is a get operation, an empty result must return a truthy Success value.</remarks>
249- public OperationResult ( TResult resultObject , ILogger loggerService ) : base ( loggerService )
249+ public OperationResult ( TResult resultObject , ILogger logger ) : base ( logger )
250250 {
251251 this . ResultObject = resultObject ;
252252 }
@@ -281,6 +281,26 @@ public OperationResult(TResult resultObject) : base()
281281 return this ;
282282 }
283283
284+ /// <summary>
285+ /// Appends an <see cref="IOperationError"/> to the internal errors collection.
286+ /// </summary>
287+ /// <param name="error">An instance of <see cref="IOperationError"/> to add to the internal errors collection.</param>
288+ /// <param name="logLevel">The logging level.</param>
289+ /// <returns>The current instance of the <see cref="OperationResult"/>.</returns>
290+ public OperationResult < TResult > AppendError ( IOperationError error , LogLevel ? logLevel = LogLevel . Error )
291+ {
292+ base . AppendErrorInternal ( error ) ;
293+
294+ if ( this . _logger is not null )
295+ {
296+ #pragma warning disable CA2254 // Template should be a static expression
297+ this . _logger . Log ( GetLogLevel ( logLevel ) , error . Message ) ;
298+ #pragma warning restore CA2254 // Template should be a static expression
299+ }
300+
301+ return this ;
302+ }
303+
284304 /// <summary>
285305 /// Appends error messages from <paramref name="otherOperationResult"/> to <paramref name="originalOperationResult"/>.
286306 /// </summary>
0 commit comments