Interaction with other Vostok libraries
The main value of Vostok.Logging – integration with other Vostok's libraries.
Logging + Context
Logging.Context lets you say, " Let's automatically add properties from context to this log."
If you use ContextualLogPrefix, you can do so:
var log = new ConsoleLog().WithContextualPrefix();
using (new ContextualLogPrefix("op-1"))
{
log.Info("Message 1!");
using (new ContextualLogPrefix("op-2"))
{
log.Info("Message 2!");
}
log.Info("Message 3!");
}
ConsoleLog.Flush();Result:
2018-12-11 16:06:37,970 INFO [op-1] Message 1!
2018-12-11 16:06:38,047 INFO [op-1] [op-2] Message 2!
2018-12-11 16:06:38,047 INFO [op-1] Message 3!Logging + Hercules
Logging.Hercules – library is for a log which output events to Hercules.
LogEvent instances are mapped into Hercules events by this rules:
Timestamp(mandatory) corresponds to:Hercules event build-timestamp - a
UtcDateTimeofTimestamp.UtcOffsettag - alongtag with offset from UTC expressed in 100-ns ticks.
MessageTemplate--->MessageTemplatetag ofstringtype.RenderedMessage--->MessageTemplaterendered to log string with templates replaced to corresponding values fromProperties.Propertiesdictionary corresponds to a container with the same name. This container contains a tag for each pair. Keys are translated as-is, and the values are handled according to following conventions:If the value is a primitive scalar or a vector of primitive scalars natively supported by Hercules (such as
int,long,guid,string, etc), it's mapped as-is.Otherwise the value gets converted to
string: either stringified directly (if it properly overridesToString()) or serialized to JSON. No further container-like structure is allowed, all values end up being 'flat'.
Exceptionobject corresponds to a container with the same name and following tags:Exception runtime type (e.g.
System.NullReferenceException) --->Typetag of typestring.Exception message --->
Messagetag of typestring.Nested exceptions (e.g.
InnerExceptionandInnerExceptionsforAggregateException) --->InnerExceptionstag of typeVectorwhich contains other exceptions in the same format.Stacktrace of exception --->
StackTracetag of typeVectorofStackFrame.StackFrameisContainerof the following tags which describe a point of code which executed when exception occured:Function- a name of function (method).Type- a type whenFunctionis declared.File- file name.Line- line number.Column- column number.
Logging + Tracing
... – library is for adding TraceId to logs.
Last updated