Overview
TheLogEvent class represents a single log event in Serilog. It encapsulates all information about a logging occurrence, including the timestamp, severity level, message template, properties, exception details, and distributed tracing identifiers.
Constructors
LogEvent(DateTimeOffset, LogEventLevel, Exception, MessageTemplate, IEnumerable<LogEventProperty>)
Construct a new log event.The time at which the event occurred.
The level of the event.
An exception associated with the event, or null.
The message template describing the event.
Properties associated with the event, including those presented in the message template.
ArgumentNullException- WhenmessageTemplateorpropertiesis null
LogEvent(DateTimeOffset, LogEventLevel, Exception, MessageTemplate, IEnumerable<LogEventProperty>, ActivityTraceId, ActivitySpanId)
Construct a new log event with distributed tracing identifiers.The time at which the event occurred.
The level of the event.
An exception associated with the event, or null.
The message template describing the event.
Properties associated with the event, including those presented in the message template.
The id of the trace that was active when the event was created, if any.
The id of the span that was active when the event was created, if any.
ArgumentNullException- WhenmessageTemplateorpropertiesis null
Properties
The time at which the event occurred.
The level of the event.
The id of the trace that was active when the event was created, if any. Returns null if no trace was active.
The id of the span that was active when the event was created, if any. Returns null if no span was active.
The message template describing the event.
Properties associated with the event, including those presented in the message template.
An exception associated with the event, or null.
Methods
RenderMessage(TextWriter, IFormatProvider)
Render the message template to the specified output, given the properties associated with the event.The output writer to render the message to.
Supplies culture-specific formatting information, or null.
RenderMessage(IFormatProvider)
Render the message template given the properties associated with the event, and return the result.Supplies culture-specific formatting information, or null.
string - The rendered message
AddOrUpdateProperty(LogEventProperty)
Add a property to the event if not already present, otherwise, update its value.The property to add or update.
ArgumentNullException- Whenpropertyis null
AddPropertyIfAbsent(LogEventProperty)
Add a property to the event if not already present.The property to add.
ArgumentNullException- Whenpropertyis null
AddPropertyIfAbsent(ILogEventPropertyFactory, string, object, bool)
Add a property to the event if not already present using a factory.Factory for creating the property to add to the event.
The name of the property.
The value of the property.
If true, and the value is a non-primitive, non-array type, then the value will be converted to a structure; otherwise, unknown types will be converted to scalars.
ArgumentNullException- Whenfactoryis null
RemovePropertyIfPresent(string)
Remove a property from the event, if present. Otherwise no action is performed.The name of the property to remove.
Static Methods
UnstableAssembleFromParts
Construct aLogEvent using pre-allocated values for internal fields. This method allows specialized callers to avoid dictionary allocation overhead.
The time at which the event occurred.
The level of the event.
An exception associated with the event, or null.
The message template describing the event.
Properties associated with the event, including those presented in the message template.
The id of the trace that was active when the event was created, if any.
The id of the span that was active when the event was created, if any.
LogEvent - A constructed log event
Exceptions:
ArgumentNullException- WhenmessageTemplateorpropertiesis null