-
-
Save INTERNALINTERFERENCE/12aa6548cb05546e4ec628704da4f0cb to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public sealed class MessageErrorsManager | |
{ | |
readonly ConcurrentDictionary<string, MessageErrorObject> errors = new(); | |
public void AddError(MessageErrorObject? error) | |
{ | |
var correlationId = CorrelationIdHelper.Get(); | |
try | |
{ | |
Log.WriteDebug($"{nameof(MessageErrorsManager)}: started.", correlationId); | |
if(error is null) | |
{ | |
Log.WriteDebug($"Error is null.", correlationId); | |
return; | |
} | |
if(errors.ContainsKey(error.Error)) | |
{ | |
Log.WriteDebug($"Increment error: {error}.", correlationId); | |
errors[error.Error].Count++; | |
return; | |
} | |
errors[error.Error] = error; | |
Log.WriteWarning($"Was error: {error}.", correlationId); | |
} | |
catch(Exception ex) | |
{ | |
Log.WriteException(ex, correlationId); | |
} | |
finally | |
{ | |
Log.WriteDebug($"{nameof(MessageErrorsManager)}: ended.", correlationId); | |
} | |
} | |
public void ClearErrors() | |
{ | |
Log.WriteDebug($"{nameof(MessageErrorsManager)}: clear errors, errors count - {errors.Count}.", null); | |
errors.Clear(); | |
} | |
public IEnumerable<string> GetCriticalHealtnessErrors() | |
{ | |
IEnumerable<string> result = Array.Empty<string>(); | |
try | |
{ | |
result = errors.Values.Where(e => e.HasCriticalHealthinessErrors).Select(e => e.Error); | |
return result; | |
} | |
catch(Exception ex) | |
{ | |
Log.WriteException(ex, null); | |
return result; | |
} | |
finally | |
{ | |
Log.WriteError($"{nameof(GetCriticalHealtnessErrors)}: return value - {result.ToJson()}.", null); | |
} | |
} | |
public bool HasCriticalHealtnessErrors() => GetCriticalHealtnessErrors().Any(); | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment