/// <summary> /// Stamp the event. /// </summary> /// <param name="loggingEvent">event to stamp</param> public virtual void StampEvent(Core.LoggingEvent loggingEvent) { var value = GetValue(loggingEvent); value = GetSanitizedValue(loggingEvent, value); SetStamp(loggingEvent, Name, value); }
/// <summary> /// The NestedLayout is tried to provide a value /// </summary> /// <param name="loggingEvent">the event to get value from</param> /// <param name="obj">value found</param> /// <returns>success of finding a NestedLayout not null</returns> protected virtual bool GetLayoutValue(Core.LoggingEvent loggingEvent, out object obj) { var layout = Option as IRawLayout; try { if (layout != null) { obj = layout.Format(loggingEvent); return(true); } else { obj = null; return(false); } } catch (Exception x) { #if LOG4NET_1_2_10_COMPATIBLE LogLog.Error("Error getting value from NestedLayout", x); #else LogLog.Error(GetType(), "Error getting value from NestedLayout", x); #endif obj = null; return(false); } }
/// <summary> /// Try to get a property value with exact match /// </summary> /// <param name="loggingEvent">the event to get value from</param> /// <param name="obj">value found</param> /// <returns>success of matching a known value</returns> protected virtual bool GetPropertyValue(Core.LoggingEvent loggingEvent, out object obj) { var name = Option as string ?? Name; obj = loggingEvent.LookupProperty(name); return(obj != null); }
/// <summary> /// If a value cannot be retrieved from the separate NestedLayout object /// a set of known vallues would be tried. If that fails too, UndefinedValue is returned. /// </summary> /// <param name="loggingEvent">the event to get values for/from</param> /// <returns>Object retrieved from logging event</returns> public virtual object Format(Core.LoggingEvent loggingEvent) { object obj; return(GetLayoutValue(loggingEvent, out obj) || GetPropertyValue(loggingEvent, out obj) || GetDefaultValue(loggingEvent, out obj) ? obj : Option ?? Name ); }
public void DoAppend(Core.LoggingEvent loggingEvent) { Events.Add(loggingEvent); var layout = Layout; var writer = new StringWriter(); if (layout != null) { layout.Format(writer, loggingEvent); } else { loggingEvent.WriteRenderedMessage(writer); } EventStrings.Add(writer.ToString()); }
/// <summary> /// Create stamp value /// </summary> /// <param name="loggingEvent">event to stamp</param> /// <returns>value to set as a stamp</returns> protected virtual Object GetValue(Core.LoggingEvent loggingEvent) { var tSys = GetTimeStampValue(AgeReference.Epoch1970, AgeReference.SystemStart, 0, false); var tApp = GetTimeStampValue(AgeReference.SystemStart, AgeReference.ApplicationStart, 0, false); var tNow = GetTimeStampValue(AgeReference.ApplicationStart, AgeReference.Now, 0, false); var seq = GetSequence(); var pid = GetProcessId(); return(String.Format( "{0};{1};{2};{3};{4};{5}" , _env.GetMachineName() , tSys , tApp , tNow , pid , seq )); }
/// <summary> /// Add a log event to the ElasticSearch Repo /// </summary> /// <param name="loggingEvent"></param> protected override void Append(Core.LoggingEvent loggingEvent) { if (string.IsNullOrEmpty(ConnectionString)) { var exception = new InvalidOperationException("Connection string not present."); ErrorHandler.Error("Connection string not included in appender.", exception, ErrorCode.GenericFailure); return; } var settings = ConnectionBuilder.BuildElsticSearchConnection(ConnectionString); var client = new LogClient(settings); var logEvent = CreateLogEvent(loggingEvent); try { client.CreateEvent(logEvent); } catch (InvalidOperationException ex) { ErrorHandler.Error("Invalid connection to ElasticSearch", ex, ErrorCode.GenericFailure); } }
/// <summary> /// Make sure the value will not change later /// </summary> /// <param name="loggingEvent"></param> /// <param name="value"></param> /// <returns></returns> protected virtual Object GetSanitizedValue(Core.LoggingEvent loggingEvent, Object value) { if (value == null) { return(null); } if (value is IFixingRequired) { value = ((IFixingRequired)value).GetFixedObject(); } if (value == null) { return(null); } if (!(value is string || value.GetType().GetTypeInfo().IsPrimitive)) { value = loggingEvent.Repository.RendererMap.FindAndRender(value); } return(value); }
/// <summary> /// Create stamp value - the <see cref="Value"/> /// </summary> /// <param name="loggingEvent">event to stamp</param> /// <returns>value to set as a stamp</returns> protected override object GetValue(Core.LoggingEvent loggingEvent) { return(Value); }
/// <summary> /// Create stamp value - thread-safe statically incremented sequence number /// </summary> /// <param name="loggingEvent">event to stamp</param> /// <returns>value to set as a stamp</returns> protected override object GetValue(Core.LoggingEvent loggingEvent) { return(GetSequence()); }
/// <summary> /// The NestedLayout is tried to provide a value /// </summary> /// <param name="loggingEvent">the event to get value from</param> /// <param name="obj">value found</param> /// <returns>success of finding a NestedLayout not null</returns> protected virtual bool GetDefaultValue(Core.LoggingEvent loggingEvent, out object obj) { obj = Option; return(true); }
public override void Format(System.IO.TextWriter writer, Core.LoggingEvent loggingEvent) { loggingEvent.Fix = Core.FixFlags.All; writer.WriteLine(Newtonsoft.Json.JsonConvert.SerializeObject(loggingEvent)); }
/// <summary> /// Store the stamp value in a property of the logging event /// </summary> /// <param name="loggingEvent">event to stamp</param> /// <param name="name">name of the stamp</param> /// <param name="value">stamp value</param> protected virtual void SetStamp(Core.LoggingEvent loggingEvent, string name, Object value) { loggingEvent.Properties[name] = value; }
/// <summary> /// Create stamp value - a time value calculated from the props /// </summary> /// <param name="loggingEvent">event to stamp</param> /// <returns>value to set as a stamp</returns> protected override object GetValue(Core.LoggingEvent loggingEvent) { return(GetTimeStampValue(TimeFrom, TimeTo, Multiplier, Round)); }
/// <summary> /// Create stamp value - process id /// </summary> /// <param name="loggingEvent">event to stamp</param> /// <returns>value to set as a stamp</returns> protected override object GetValue(Core.LoggingEvent loggingEvent) { return(GetProcessId()); }