Table of Contents

Class Helper

Namespace
Arc4u.Diagnostics
Assembly
Arc4u.Diagnostics.Serilog.dll

Helper methods to read the Arc4u properties of a Serilog Serilog.Events.LogEvent.

public static class Helper
Inheritance
Helper
Inherited Members

Methods

ExtractEventInfo(LogEvent)

Extract from the LogEventProperties the Arc4u standard ones. The non standard one are added in the Properties list. Remove State property, used by Serilog to store the message!

public static (MessageCategory Category, string Application, string Identity, string ClassType, string MethodName, string ActivityId, int ProcessId, int ThreadId, string Stacktrace, List<LogEventProperty> Properties) ExtractEventInfo(LogEvent logEvent)

Parameters

logEvent LogEvent

The Serilog event.

Returns

(MessageCategory Category, string Application, string Identity, string ClassType, string MethodName, string ActivityId, int ProcessId, int ThreadId, string Stacktrace, List<LogEventProperty> Properties)

A tuple with the Arc4u standard properties (category, application, identity, class, method, activity id, process id, thread id, stack trace; a default value when absent) and the list of the other properties. The category is Technical when it is absent or not a category (see GetCategory(LogEventPropertyValue)).

GetCategory(LogEventPropertyValue)

Reads the Arc4u MessageCategory from a property value. The category is written by the logger as a string but, depending on the pipeline, it reaches the sink as the enum itself, its name (e.g. "Monitoring") or its numeric value. A category is a short flag: a category invented by the application is read from the name registered with MessageCategoryRegistry (e.g. "Security") or from its number (e.g. "8").

public static MessageCategory? GetCategory(LogEventPropertyValue pv)

Parameters

pv LogEventPropertyValue

The property value.

Returns

MessageCategory?

The category, or null when the value is not a scalar, not a predefined or registered name, or not a positive short.

GetValue<T>(LogEventPropertyValue, T)

Gets the value of a scalar property.

public static T GetValue<T>(LogEventPropertyValue pv, T defaultValue)

Parameters

pv LogEventPropertyValue

The property value.

defaultValue T

The value returned when pv is not a scalar or its value is not of type T.

Returns

T

The typed scalar value, or defaultValue.

Type Parameters

T

The expected type of the value.

ToMessageType(LogEventLevel)

Converts a Serilog Serilog.Events.LogEventLevel to the corresponding LogLevel; unknown values map to Debug.

public static LogLevel ToMessageType(this LogEventLevel level)

Parameters

level LogEventLevel

The Serilog level.

Returns

LogLevel

The equivalent LogLevel.