/// <summary> /// Writes a log entry. /// </summary> /// <param name="timestamp"></param> /// <param name="logLevel">Entry will be written on this level.</param> /// <param name="eventId">Id of the event.</param> /// <param name="state">The entry to be written. Can be also an object.</param> /// <param name="exception">The exception related to this entry.</param> /// <param name="formatter"> /// Function to create a <c>string</c> message of the /// <paramref name="state" /> and /// <paramref name="exception" />. /// </param> public void Log <TState>(System.DateTimeOffset timestamp, Microsoft.Extensions.Logging.LogLevel logLevel, Microsoft.Extensions.Logging.EventId eventId, TState state, System.Exception exception, System.Func <TState, System.Exception, System.String> formatter) { if (!this.IsEnabled(logLevel)) { return; } // new Internal.Generic.LogMessage<TState>(logLevel, eventId, state, exception, // formatted, logType, timestamp, correlationId); var builder = new Generic.LogMessage <TState>(logLevel: logLevel, eventId: eventId, state: state, exception: exception, formatter: formatter, logType: this._categoryNameLogType, timestamp: timestamp); this._provider.AddMessage(builder); }
private new void Log <TState>( Microsoft.Extensions.Logging.LogLevel logLevel, Microsoft.Extensions.Logging.EventId eventId, [JetBrains.Annotations.NotNull] TState state, System.Exception exception, [JetBrains.Annotations.NotNull] System.Func <TState, System.Exception, System.String> formatter) { #if DEBUG System.Console.WriteLine($"{{ {System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.FullName}.{System.Reflection.MethodBase.GetCurrentMethod().Name} }}"); #endif var builder = new Generic.LogMessage <TState>(logLevel, eventId, state, exception, formatter, this._categoryNameLogType); this._provider.AddMessage(builder); }
protected internal void AddMessage(Generic.LogMessage <System.Object> message) { if (this.MessageQueue.IsAddingCompleted) { return; } try { this.MessageQueue.Add(message, this.CancellationTokenSource.Token); } catch { //TODO cancellation token canceled or CompleteAdding called } }
/// <summary> /// Writes a log entry /// </summary> /// <typeparam name="TState"></typeparam> /// <param name="logType"></param> /// <param name="timestamp"></param> /// <param name="logLevel"></param> /// <param name="eventId"></param> /// <param name="state"></param> /// <param name="exception"></param> /// <param name="formatter"></param> /// <param name="correlationId"></param> public void Log <TState>( [JetBrains.Annotations.CanBeNull] Microsoft.Extensions.Logging.LogLevel?logLevel, Microsoft.Extensions.Logging.EventId eventId, [JetBrains.Annotations.NotNull] TState state, [JetBrains.Annotations.CanBeNull] System.Exception exception, [JetBrains.Annotations.NotNull] System.Func <TState, System.Exception, System.String> formatter, // ReSharper disable once UnusedParameter.Global [JetBrains.Annotations.CanBeNull] System.String logType = null, [JetBrains.Annotations.CanBeNull] System.DateTimeOffset?timestamp = null, [JetBrains.Annotations.CanBeNull] System.Guid?correlationId = null) { #if DEBUG System.Console.WriteLine($"{{ {System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.FullName}.{System.Reflection.MethodBase.GetCurrentMethod().Name} }}"); #endif var builder = new Generic.LogMessage <TState>(logLevel, eventId, state, exception, formatter, this._categoryNameLogType, timestamp, correlationId); this._provider.AddMessage(builder); }
protected internal static (System.Int32 Year, System.Int32 Month, System.Int32 Day) GetGrouping(Generic.LogMessage <System.Object> message) => (message.Timestamp.Year, message.Timestamp.Month, message.Timestamp.Day);
public void Init() { this.TestContext.WriteLine($"{{ {System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.FullName}.{System.Reflection.MethodBase.GetCurrentMethod().Name} }}"); // ReSharper disable once LocalNameCapturedOnly String hr; var exception1 = new ArgumentNullException(nameof(hr), "LogMessageTestExceptionNoEvent Broke"); var correlationId = Guid.NewGuid(); this._logMessage1 = new Generic.LogMessage <ArgumentNullException>() { CorrelationId = correlationId, //EventId = new Microsoft.Extensions.Logging.EventId(101010); Exception = exception1, //Formatted = new System.Func<System.String, System.Exception, System.String>((state, ex) => this.GetType().ToString()), LogLevel = LogLevel.Trace, LogType = System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.FullName.RemoveAllSpecialCharacters(), State = exception1, Timestamp = DateTime.Now }; var exception2 = new Exception("This stupid thing broke!", exception1); this._logMessage2 = new Generic.LogMessage <Exception>() { CorrelationId = correlationId, //EventId = new Microsoft.Extensions.Logging.EventId(101010); Exception = exception2, // Formatted = new System.Func<System.String, System.Exception, // System.String>((state, ex) => this.GetType().ToString()), LogLevel = LogLevel.Trace, LogType = System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.FullName.RemoveAllSpecialCharacters(), State = exception2, Timestamp = DateTime.Now }; this._logMessage3 = new Generic.LogMessage <String>() { CorrelationId = correlationId, EventId = new EventId(101010), //Exception = exception, // Formatted = new System.Func<System.String, System.Exception, System.String>((state, ex) => this.GetType().ToString()), LogLevel = LogLevel.Debug, LogType = System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.FullName.RemoveAllSpecialCharacters(), State = "LogMessageTestInnerExceptionNoEvent System.String State", Timestamp = DateTime.Now }; this._logMessage4 = new Generic.LogMessage <String>() { CorrelationId = correlationId, //EventId = new Microsoft.Extensions.Logging.EventId(101010), //Exception = exception, //Formatted = "", LogLevel = LogLevel.Debug, LogType = System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.FullName.RemoveAllSpecialCharacters(), State = "LogMessageTestNoExceptionNoEvent State", Timestamp = DateTime.Now }; }