Beispiel #1
0
        public void Log(LogLevel level, IGeneralComponent component, IGeneralComponent relatedComponent, string message, Exception ex = null, DateTime?createAt = null)
        {
            _logs.Enqueue(new LoggingModel
            {
                SessionId          = _sessionId,
                ComponentId        = component.GetId(),
                RelatedComponentId = relatedComponent?.GetId(),
                CreatedAt          = createAt ?? DateTime.Now,
                Level     = level,
                Message   = message,
                Exception = ex?.ToString()
            });

            var loggerName = component.GetName();

            if (relatedComponent != null)
            {
                loggerName += $": ({relatedComponent.GetName()})";
            }
            var l   = _loggers.GetOrAdd(loggerName, _logger.CreateLogger(loggerName));
            var msg = $"{createAt ?? DateTime.Now:s} {message}";

            switch (level)
            {
            case LogLevel.Trace:       l.LogTrace(0, ex, msg); break;

            case LogLevel.Debug:       l.LogDebug(0, ex, msg); break;

            case LogLevel.Information: l.LogInformation(0, ex, msg); break;

            case LogLevel.Warning:     l.LogWarning(0, ex, msg); break;

            case LogLevel.Error:       l.LogError(0, ex, msg); break;

            case LogLevel.Critical:    l.LogCritical(0, ex, msg); break;
            }
        }
Beispiel #2
0
 public void ComponetStarted(IGeneralComponent component)
 {
     Log(LogLevel.Information, component, $"Started ({component.GetName()}:{component.GetId()})");
 }