/// <summary> /// Logs the message. /// </summary> /// <param name="level">The logging level.</param> /// <param name="messageEntity">The message entity.</param> protected override void InternalLog(LogLevel level, LogMessageTableEntity messageEntity) { if (this._blobContainer != null) { try { string logFile = $"{LogsRootFolder}/{messageEntity.Timestamp.ToString(YearFormat, CultureInfo.InvariantCulture)}/{messageEntity.Timestamp.ToString(MonthFormat, CultureInfo.InvariantCulture)}/{messageEntity.Timestamp.ToString(DayFormat, CultureInfo.InvariantCulture)}/{messageEntity.Timestamp.ToString(TimeFormat, CultureInfo.InvariantCulture)}.log"; this._blobContainer.AppendBlobAppendText(logFile, messageEntity.ToString() + Environment.NewLine); } catch (Exception e) { var internalError = InternalLogger.Log(e); try { string logFile = $"{LogsRootFolder}/internal/{messageEntity.Timestamp.ToString(TimeFormat, CultureInfo.InvariantCulture)}.log"; this._blobContainer.AppendBlobAppendText(logFile, internalError + Environment.NewLine); this._blobContainer.AppendBlobAppendText(logFile, messageEntity.ToString() + Environment.NewLine); } catch (Exception ex) { InternalLogger.Log(ex); } } } else { InternalLogger.Log("DevLib.Azure.Logging.BlobLogger._blobContainer is null"); } }
/// <summary> /// Logs the message. /// </summary> /// <param name="level">The logging level.</param> /// <param name="messageEntity">The message entity.</param> protected override void InternalLog(LogLevel level, LogMessageTableEntity messageEntity) { if (this._tableStorage != null) { try { this._tableStorage.Insert(messageEntity); } catch (Exception e) { var internalError = InternalLogger.Log(e); try { messageEntity.RowKey = $"InternalError[{Guid.NewGuid().ToString().Replace("-", string.Empty).ToLowerInvariant()}]"; messageEntity["InternalError"] = internalError; this._tableStorage.Insert(messageEntity); } catch (Exception ex) { InternalLogger.Log(ex); } } } else { InternalLogger.Log("DevLib.Azure.Logging.TableLogger._tableStorage is null"); } }
/// <summary> /// Logs the message with specified level. /// </summary> /// <param name="level">The logging level.</param> /// <param name="messages">The messages.</param> /// <param name="applicationName">Name of the application.</param> /// <param name="eventId">The event identifier.</param> /// <param name="instanceId">The instance identifier.</param> /// <returns>The current ILogger instance.</returns> private ILogger InternalLog(LogLevel level, object[] messages, string applicationName, string eventId, string instanceId) { if (level < this.LogLevelCriteria) { return(this); } var messageEntity = new LogMessageTableEntity { Level = level.ToString(), Message = messages != null?string.Join(", ", messages.Select(i => i?.ToString() ?? string.Empty)) : string.Empty, StackTrace = GetStackFrameInfo(2), EventId = eventId, InstanceId = instanceId }; if (!string.IsNullOrWhiteSpace(applicationName)) { messageEntity.ApplicationName = applicationName; } this.InternalLog(level, messageEntity); return(this); }
/// <summary> /// Logs the message with specified level. /// </summary> /// <param name="level">The logging level.</param> /// <param name="message">The message.</param> /// <param name="applicationName">Name of the application.</param> /// <param name="eventId">The event identifier.</param> /// <param name="instanceId">The instance identifier.</param> /// <returns>The global logger instance.</returns> private static ILogger InternalLog(LogLevel level, object message, string applicationName, string eventId, string instanceId) { if (level < LogLevelCriteria) { return(GlobalLogger); } var messageEntity = new LogMessageTableEntity { Level = level.ToString(), Message = message?.ToString() ?? string.Empty, StackTrace = GetStackFrameInfo(2), EventId = eventId, InstanceId = instanceId }; if (!string.IsNullOrWhiteSpace(applicationName)) { messageEntity.ApplicationName = applicationName; } InternalLog(level, messageEntity); return(GlobalLogger); }
/// <summary> /// Logs the message. /// </summary> /// <param name="level">The logging level.</param> /// <param name="messageEntity">The message entity.</param> protected override void InternalLog(LogLevel level, LogMessageTableEntity messageEntity) { try { if (level == LogLevel.ALL || level == LogLevel.DBG || level == LogLevel.INF) { Trace.TraceInformation(messageEntity.ToString()); } else if (level == LogLevel.WRN) { Trace.TraceWarning(messageEntity.ToString()); } else if (level == LogLevel.EXP || level == LogLevel.ERR) { Trace.TraceError(messageEntity.ToString()); } else if (level == LogLevel.FAL) { Trace.TraceError(messageEntity.ToString()); Trace.Fail(messageEntity.ToString()); } else { Trace.WriteLine(messageEntity.ToString()); } } catch (Exception e) { InternalLogger.Log(e); } }
/// <summary> /// Logs the specified message entity. /// </summary> /// <param name="messageEntity">The message entity.</param> /// <returns>The current ILogger instance.</returns> public ILogger Log(LogMessageTableEntity messageEntity) { if (messageEntity != null) { this.InternalLog(LogLevel.ALL, messageEntity); } return(this); }
/// <summary> /// Logs the specified message entity. /// </summary> /// <param name="level">The logging level.</param> /// <param name="messageEntity">The message entity.</param> /// <returns>The current ILogger instance.</returns> public ILogger Log(LogLevel level, LogMessageTableEntity messageEntity) { if (messageEntity != null && level != LogLevel.OFF) { this.InternalLog(level, messageEntity); } return(this); }
/// <summary> /// Logs the specified message entity. /// </summary> /// <param name="level">The logging level.</param> /// <param name="messageEntity">The message entity.</param> /// <returns>The global logger instance.</returns> public static ILogger Log(LogLevel level, LogMessageTableEntity messageEntity) { if (messageEntity != null && level != LogLevel.OFF) { InternalLog(level, messageEntity); } return(GlobalLogger); }
/// <summary> /// Logs the specified message entity. /// </summary> /// <param name="messageEntity">The message entity.</param> /// <returns>The global logger instance.</returns> public static ILogger Log(LogMessageTableEntity messageEntity) { if (messageEntity != null) { InternalLog(LogLevel.ALL, messageEntity); } return(GlobalLogger); }
/// <summary> /// Logs the message. /// </summary> /// <param name="level">The logging level.</param> /// <param name="messageEntity">The message entity.</param> protected override void InternalLog(LogLevel level, LogMessageTableEntity messageEntity) { try { if (level == LogLevel.EXP || level == LogLevel.ERR || level == LogLevel.FAL) { Debug.Fail(messageEntity.ToString()); } Debug.WriteLine(messageEntity.ToString()); } catch (Exception e) { InternalLogger.Log(e); } }
/// <summary> /// Logs the message. /// </summary> /// <param name="level">The logging level.</param> /// <param name="messageEntity">The message entity.</param> protected override void InternalLog(LogLevel level, LogMessageTableEntity messageEntity) { try { lock (ConsoleSyncRoot) { ConsoleColor originalForeColor = Console.ForegroundColor; Console.ForegroundColor = ConsoleColorDictionary[level]; Console.WriteLine(messageEntity.ToString()); Console.WriteLine(); Console.ForegroundColor = originalForeColor; } } catch (Exception e) { InternalLogger.Log(e); } }
/// <summary> /// Logs the message. /// </summary> /// <param name="level">The logging level.</param> /// <param name="messageEntity">The message entity.</param> protected override void InternalLog(LogLevel level, LogMessageTableEntity messageEntity) { try { foreach (var logger in this._loggers) { try { logger.Log(level, messageEntity); } catch (Exception e) { InternalLogger.Log(e); } } } catch (Exception e) { InternalLogger.Log(e); } }
/// <summary> /// Logs the message. /// </summary> /// <param name="level">The logging level.</param> /// <param name="messageEntity">The message entity.</param> protected virtual void InternalLog(LogLevel level, LogMessageTableEntity messageEntity) { }
/// <summary> /// Logs the message. /// </summary> /// <param name="level">The logging level.</param> /// <param name="messageEntity">The message entity.</param> private static void InternalLog(LogLevel level, LogMessageTableEntity messageEntity) { GlobalLogger.Log(level, messageEntity); }