public interface ILogger

NuGet Package        KissLog
Namespace        KissLog

ILogger represents the principal component used to write log messages.


Log levels

ILogger exposes all the log levels used by .NET Framework.

Level Usage
Trace _logger.Trace("Database connection opened");
Debug _logger.Debug("Two factor authentication started");
Information _logger.Info($"Recover password email sent for email ");
Warning _logger.Warn($"Cache entry for was not found");
Error _logger.Error($"User with Id = was not found");
Critical _logger.Critical("There is not enough space on the disk. Save failed.");

Log arguments

Each log method accepts multiple arguments overloads.

Argument Usage
string _logger.Info("String value");
object _logger.Warn(new );
System.Exception _logger.Error(ex);
Args _logger.Dubug(new Args("Creating product", 30, product));

Logging files

ILogger exposes methods which allows developers to save raw data as files.

When a file is logged, a temporary copy is created. The original file is not altered or referenced.

The temporary files are automaticaly discarded at the end of the Http Request.

Argument Usage
byte[] content byte[] archive = File.ReadAllBytes(@"C:\Files\");
_logger.LogAsFile(archive, "");
string content string xml = File.ReadAllText(@"C:\Files\cd_catalog.xml");
_logger.LogAsFile(xml, "Catalog.xml");
filePath string path = @"C:\Files\Invoice-16-11-2017.pdf";
_logger.LogFile(path, "Invoice.pdf");

Acquiring ILogger instance

An ILogger instance is created and shared automatically per each Http Request.

To retreive the ILogger, use Logger.Factory.Get() factory method.

Calling this method multiple times will return the same ILogger instance per Http Request.

ILogger logger = Logger.Factory.Get(string categoryName = "Default");

ILogger can be integrated using Dependency Injection, and, in most of the situations, you won't need to create the ILogger instance manually.