This logging library makes large use of enterprise correlation. In a lot of applications that incorporate various small and large services, it is often important to correlate events that happen across these services. It gives us a business workflow view of the various events that happen in the application, its components and services. This library provide operation and activity ID management and propagation. The main difference with this library over other is that you can configure each type of log separately. You can enable fatal, error, warning, debugging, informational, progress and sensitive data logging all independently of each other. This is more flexible than the concept of minimum level logging, such as that in log4net or serilog e.g. enabling one warning in this libraries will enable error and fatal logging as well. This library allows you to set those settings independently of each other. The SqlLogger maps AdditionalData to table columns, where the key of the dictionary entry is the column name and the value is serialised to JSON as the column value. MetaData is serialised to a single JSON value stored in the MetaData column. This means you can store data such as a User ID or Job ID in a separate column so you can filter more efficiently with indexes and partitions. TraceLogger and ConsoleLogger both seralise and format all information into a single string. The MultiLogger allows you to configure several different loggers to be used at once with different settings for each logger. Usage is in the form of: static void Main() {   ICorrelationIdHelper correlationIdHelper = new WebCorrelationIdHelper();   // This value will be set automatically to all logs within this thread... so long as System.Threading.Tasks.Task.Factory.StartNew is used.   correlationIdHelper.SetCorrelationId(Guid.NewGuid());   DoSyncWork();   DoAsyncWork(); } static void DoSyncWork() {   ILogger logger = new SqlLogger();   logger.LogDebug("Some technical debugging details."); } static void DoAsyncWork() {   System.Threading.Tasks.Task.Factory.StartNew(() => {     ILogger logger = new ConsoleLogger();     logger.LogInfo("An informative message.");   }); } This package installs cdmdotnet.Logging.dll with includes core logging functionality. Other packages depend on cdmdotnet.Logging for specific implementations.


Keywords
License
Apache-2.0
Install
Install-Package cdmdotnet.Logging -Version 1.0.11.12

Documentation

C# Logging

An abstracted logging platform for .NET. It can help you collect reliable logs for your application regardless of its size or complexity with minimal performance implications.

Nuget Packages:

  • Chinchilla.Logging - core library with Console and Trace based outputs
  • Chinchilla.Logging.Azure - an Azure based package to store outputs in Azure Log Analytics and/or to allow configuration settings to be set via the Azure portal
  • Chinchilla.Logging.Azure.ApplicationInsights - an Azure based package to add Telemetry automatically as a result of logging to ApplicationInsights
  • Chinchilla.Logging.Azure.Storage - an Azure based package to store outputs in Azure Table Storage
  • Chinchilla.Logging.Sql - a SqlServer based package to store outputs in SqlServer.
  • Chinchilla.Logging.Serilog - a Serilog based package to store outputs using Serilog.

The CorrelationId and ICorrelationIdHelper

A CorrelationId is an identifier used to group together logs. This might be all logs as a result of calling a webform or MVC controller action. To use it add the following to your global.asax.cs, replacing NinjectDependencyResolver with your dependency resolver of choice.

	protected void Application_BeginRequest(object sender, EventArgs e)
	{
		NinjectDependencyResolver.Current.Resolve<ICorrelationIdHelper>().SetCorrelationId(Guid.NewGuid());
	}

There are three built-in ICorrelationIdHelper implementations, CorrelationIdHelper, WebCorrelationIdHelper and NullCorrelationIdHelper

WebCorrelationIdHelper is for use on a website. CorrelationIdHelper is for use in a console app, windows service, winform or other such application not managed by IIS. NullCorrelationIdHelper is for use in unit and integration tests. It always returns Guid.Empty

ILogger Implementations

TraceLogger

ConsoleLogger

SqlLogger

SerilogLogger

TableStorageLogger

LogAnalyticsLogger

MultiLogger - for those odd times you need to use multiple technology stacks for logging.