JD2022-TU1/main/tools/framework/JD.LogService/ObservedLogging.cs

26 lines
No EOL
739 B
C#

using System;
namespace JD.LogService
{
/// <summary>
/// Helper to observe logging actions.
/// </summary>
public static class ObservedLogging
{
/// <summary>
/// True if the action cause errors to be logged in the log.
/// </summary>
public static bool LogsError(ILogger wrappedLog, Action<ILogger> loggingAction)
{
bool hasLoggedEvent = false;
ILogger observedLogger = Logger.FromAction(delegate(LogEvent @event)
{
wrappedLog.Log(@event);
hasLoggedEvent |= @event.Category == LogCategory.Error;
});
loggingAction(observedLogger);
return hasLoggedEvent;
}
}
}