Class LogEvent
A log event.
public class LogEvent- Inheritance
- 
      
      LogEvent
- Inherited Members
Constructors
LogEvent(DateTimeOffset, LogEventLevel, Exception?, MessageTemplate, IEnumerable<LogEventProperty>)
Construct a new LogEvent.
public LogEvent(DateTimeOffset timestamp, LogEventLevel level, Exception? exception, MessageTemplate messageTemplate, IEnumerable<LogEventProperty> properties)Parameters
- timestampDateTimeOffset
- The time at which the event occurred. 
- levelLogEventLevel
- The level of the event. 
- exceptionException
- An exception associated with the event, or null. 
- messageTemplateMessageTemplate
- The message template describing the event. 
- propertiesIEnumerable<LogEventProperty>
- Properties associated with the event, including those presented in - messageTemplate.
Exceptions
- ArgumentNullException
- When - messageTemplateis- null
- ArgumentNullException
- When - propertiesis- null
LogEvent(DateTimeOffset, LogEventLevel, Exception?, MessageTemplate, IEnumerable<LogEventProperty>, ActivityTraceId, ActivitySpanId)
Construct a new LogEvent.
[CLSCompliant(false)]
public LogEvent(DateTimeOffset timestamp, LogEventLevel level, Exception? exception, MessageTemplate messageTemplate, IEnumerable<LogEventProperty> properties, ActivityTraceId traceId, ActivitySpanId spanId)Parameters
- timestampDateTimeOffset
- The time at which the event occurred. 
- levelLogEventLevel
- The level of the event. 
- exceptionException
- An exception associated with the event, or null. 
- messageTemplateMessageTemplate
- The message template describing the event. 
- propertiesIEnumerable<LogEventProperty>
- Properties associated with the event, including those presented in - messageTemplate.
- traceIdActivityTraceId
- The id of the trace that was active when the event was created, if any. 
- spanIdActivitySpanId
- The id of the span that was active when the event was created, if any. 
Exceptions
- ArgumentNullException
- When - messageTemplateis- null
- ArgumentNullException
- When - propertiesis- null
Properties
Exception
An exception associated with the event, or null.
public Exception? Exception { get; }Property Value
Level
The level of the event.
public LogEventLevel Level { get; }Property Value
MessageTemplate
The message template describing the event.
public MessageTemplate MessageTemplate { get; }Property Value
Properties
Properties associated with the event, including those presented in MessageTemplate.
public IReadOnlyDictionary<string, LogEventPropertyValue> Properties { get; }Property Value
SpanId
The id of the span that was active when the event was created, if any.
[CLSCompliant(false)]
public ActivitySpanId? SpanId { get; }Property Value
Timestamp
The time at which the event occurred.
public DateTimeOffset Timestamp { get; }Property Value
TraceId
The id of the trace that was active when the event was created, if any.
[CLSCompliant(false)]
public ActivityTraceId? TraceId { get; }Property Value
Methods
AddOrUpdateProperty(LogEventProperty)
Add a property to the event if not already present, otherwise, update its value.
public void AddOrUpdateProperty(LogEventProperty property)Parameters
- propertyLogEventProperty
- The property to add or update. 
Exceptions
- ArgumentNullException
- When - propertyis- null
AddPropertyIfAbsent(LogEventProperty)
Add a property to the event if not already present.
public void AddPropertyIfAbsent(LogEventProperty property)Parameters
- propertyLogEventProperty
- The property to add. 
Exceptions
- ArgumentNullException
- When - propertyis- null
RemovePropertyIfPresent(string)
Remove a property from the event, if present. Otherwise no action is performed.
public void RemovePropertyIfPresent(string propertyName)Parameters
- propertyNamestring
- The name of the property to remove. 
RenderMessage(IFormatProvider?)
Render the message template given the properties associated with the event, and return the result.
public string RenderMessage(IFormatProvider? formatProvider = null)Parameters
- formatProviderIFormatProvider
- Supplies culture-specific formatting information, or null. 
Returns
RenderMessage(TextWriter, IFormatProvider?)
Render the message template to the specified output, given the properties associated with the event.
public void RenderMessage(TextWriter output, IFormatProvider? formatProvider = null)Parameters
- outputTextWriter
- The output. 
- formatProviderIFormatProvider
- Supplies culture-specific formatting information, or null. 
UnstableAssembleFromParts(DateTimeOffset, LogEventLevel, Exception?, MessageTemplate, Dictionary<string, LogEventPropertyValue>, ActivityTraceId, ActivitySpanId)
Construct a LogEvent using pre-allocated values for internal fields. Normally, the LogEvent constructor allocates a dictionary to back Properties, so that this is not unexpectedly shared. This is unnecessary in many integration scenarios, leading to an additional nontrivial Dictionary<TKey, TValue> allocation. This method allows specialized callers to avoid that overhead.
[CLSCompliant(false)]
public static LogEvent UnstableAssembleFromParts(DateTimeOffset timestamp, LogEventLevel level, Exception? exception, MessageTemplate messageTemplate, Dictionary<string, LogEventPropertyValue> properties, ActivityTraceId traceId, ActivitySpanId spanId)Parameters
- timestampDateTimeOffset
- The time at which the event occurred. 
- levelLogEventLevel
- The level of the event. 
- exceptionException
- An exception associated with the event, or null. 
- messageTemplateMessageTemplate
- The message template describing the event. 
- propertiesDictionary<string, LogEventPropertyValue>
- Properties associated with the event, including those presented in - messageTemplate.
- traceIdActivityTraceId
- The id of the trace that was active when the event was created, if any. 
- spanIdActivitySpanId
- The id of the span that was active when the event was created, if any. 
Returns
Remarks
Because this method exposes parameters that essentially map 1:1 with internal fields of LogEvent, the parameter list may change across major Serilog versions.
Exceptions
- ArgumentNullException
- When - messageTemplateis- null
- ArgumentNullException
- When - propertiesis- null