Logging Introduction VirtoCommerce logging system is based on Symantic Logging Application Block. The VirtoCommerce.Slab project has the base classes that should be used in order to log application outputs, events, information, everything needs to be logged. Overview The logging system basics are: EventSource EventCodes Context SlabInvoker Write (log) extension EventSource EventSource is the base class that has basic logging methods and needs to be extended with logging methods (Events). Those events should describe what information has to be logged using input parameters. Attributes describes the level of the log, keyword, message format, event code. EventCodes EventCode is the unique code of the event in the scope of the EventSource. In order to ease EventCode uniqueness validation EventCodes are defined as constants in the EventSource class directly. Context Context is the placeholder to store data that needs to be logged. The BaseSlabContext is implemented in the VirtoCommerce.Slab project. SlabInvoker SlabInvoker is the helper class to use with BaseSlabContext or inherited classes. It should be used in the long running tasks to log basic information on the task. That is start time, end time, duration, error if any. The SlabInvoker also has OnSuccess, OnError, OnFinished delegates that can be invoked after the long running task is completed or if error occurred. Write extension Write(this EventSource, int EventCode, object Context) is an extension method over the EventSource class. It has two input parameters – the EventCode to call the appropriate Event of the particular EventSource and the Context passed to log the event. To use the Write extension method – fill the information to be logged into the Context pass it with the EventCode into the method. The internal code will parse the context and match the Event method parameters with the Context properties by name (Case-Sensitive). If the Event with the code found in the EventSource and all the required parameters will be filled, the Event will be raised. Extending the Semantic Logging The VirtoCommerce.Slab has base classes to implement logging functionality. Use it to implement your own Contexts and Event sources to extend the base classes to match the logging requirements. BaseSlabContext BaseSlabContext can be used as the base class for any logging Context. It contains StartTime, EndTime, Duration, Exception, Error, HasError properties. Those can be useful in most logging tasks. In order to extend the context with required properties, create class that will inherit the BaseSlabContext class. Developing logs using VirtoCommerce semantic logging system This section explains how you can use the VirtoCommerce.Slab library and how you implement different event logging scenarios within your applications and services. In the next example we will add logs into PaymentGateways module. Once you decided to put anything into log you need to add reference to the VirtoCommerce.Slab project in order to be able to use base classes described above. Add new class and name it PaymentGatewaysEventSource that is inherited from the EventSource. Add attribute EventSource to the PaymentGatewaysEventSource class: [EventSource(Name = VCEventSources.Base)] public class PaymentGatewaysEventSource : EventSource { } The class is the placeholder for Event methods. Now add EventCodes class into the PaymentGatewaysEventSource class. The EventCodes class will store unique Event ids constants. The class will be filled once new Event is added to the PaymentGatewaysEventSource. [EventSource(Name = VCEventSources.Base)] public class PaymentGatewaysEventSource : EventSource { public class EventCodes { public const int PaymentOperationInfo = 11000; public const int PaymentOperationError = 11001; } }