private void InitInternal(ICacheManager cache, IExceptionLogger exceptionLogger, ILogger logger) { this.cache = cache; this.exceptionLogger = exceptionLogger; this.logger = logger; CultureDependentTextExtension = ".cdt"; CultureIndependentTextExtension = ".cit"; Logger.LogCategory($"{this.GetType().Name}.init()"); Logger.Log($"Cache: {cache?.GetType().Name}"); Logger.Log($"ExceptionLogger: {exceptionLogger?.GetType().Name}"); Logger.Log($"Logger: {logger?.GetType().Name}"); cacheItemName = "__translator"; if (cache != null) { try { Logger.Log($"Restoring items from cache"); _store = cache.Get <Dictionary <string, string[]> >(CacheItemName); _storenames = cache.Get <Dictionary <string, string[]> >(CacheItemName + ".names"); } catch (Exception e) { Logger.Log($"Restore failed."); exceptionLogger.LogException(e, $"{this.GetType().Name}.init()"); _store = null; _storenames = null; } } if (_store == null) { _store = new Dictionary <string, string[]>(StringComparer.CurrentCultureIgnoreCase); _storenames = new Dictionary <string, string[]>(StringComparer.CurrentCultureIgnoreCase); } Init(cache, exceptionLogger, logger); }
public void AddLogger(IExceptionLogger logger) { if (logger.IsNull()) { throw new ArgumentNullException(); } var recurrentLoggers = from tempLogger in loggers where tempLogger.GetType() == logger.GetType() select tempLogger; // Прерывает выполнение, если в списке логгеров уже есть логгер с данным типом. if (recurrentLoggers.GetEnumerator().MoveNext()) { throw new InvalidOperationException(); } loggers.Add(logger); }
private static async Task SaveAsync(ExceptionData exData) { try { foreach (IExceptionLogger exceptionLogger in ConfigurationController.ExceptionLoggers) { IExceptionLogger exLogger = exceptionLogger; try { using (new TransactionScope(TransactionScopeOption.Suppress)) { if (exLogger is IExceptionLoggerAsync) { await((IExceptionLoggerAsync)exLogger).LogExceptionAsync(exData); } else { exLogger.LogException(exData); } } } catch (Exception ex) { OMFException dwdEx = new OMFException(string.Format("{0} exception: {1}", (object)exLogger.GetType().FullName, (object)ex.Message), exData.Exception); string message = ExceptionManager.GetExceptionMessageWithDebugInfo((Exception)dwdEx); EventLogHelper.Write(message, EventLogEntryType.Error); continue; } exLogger = (IExceptionLogger)null; } } catch (Exception ex) { throw new LogManagementException("[ExceptionServiceLoggerName] failed and throw an exception", ex); } }