Logger
Overview
VersaTul.Logger provides the core logging abstractions shared by the file, mail, and web logger packages.
It defines a consistent logging contract, a standard log payload model, log levels, and a parser that can turn log events and exceptions into tabular, HTML, or JSON output.
Why Use This Package
Use this package when you want one logging contract that can survive changes in delivery target.
Its value is the shared model: application code can emit LogInfo and exceptions once, while sink packages decide where those logs end up.
When To Use This Package
Use this package when you want to:
Define your own logger implementation against a common VersaTul contract.
Log both structured
LogInfoentries and exceptions through the same interface.Reuse shared parsing and formatting logic across multiple log sinks.
Keep application code independent from any single logging transport.
Installation
Install the package with the .NET CLI:
dotnet add package VersaTul.Logger
Or with the Package Manager Console:
PM> NuGet\Install-Package VersaTul.Logger -Version latest
Start Here If
You want application code to depend on a logger contract instead of a concrete sink.
You need shared parsing and payload formatting across several logging outputs.
You may add or change sinks later.
Not The Right First Package If
You need logs written somewhere immediately and have not chosen a sink package.
You are looking for email delivery or file rotation behavior rather than shared logging contracts.
Works Well With
Logger File for local disk logging.
Logger Mail for email-based alerting.
Logger Web for HTTP-based transport.
Logging Setup Workflow when you want the fastest useful logging workflow.
Core Types And Concepts
ILoggerDefines sync and async overloads for logging
LogInfo,Exception, or both together.LogInfoStandard log payload containing level, category, date, message, and optional trace identifier.
ILogParserandLogParserConvert log payloads and exception chains into
Tab,Html, orJsonoutput.LogLevelRepresents the severity of a log entry.
Key Capabilities
Log entries can be emitted synchronously or asynchronously.
LogInfosupports correlation throughTraceId.LogParserwalks inner exceptions and emits multi-depth exception details.The parser supports output formats suitable for files, emails, and web payloads.
Basic Example
using VersaTul.Logger;
using VersaTul.Logger.Contracts;
public class DatabaseLogger : ILogger
{
private readonly ILogParser logParser;
public DatabaseLogger(ILogParser logParser)
{
this.logParser = logParser;
}
public void Log(Exception exception) => LogAsync(exception).GetAwaiter().GetResult();
public void Log(LogInfo logInfo) => LogAsync(logInfo).GetAwaiter().GetResult();
public void Log(LogInfo logInfo, Exception exception) => LogAsync(logInfo, exception).GetAwaiter().GetResult();
public Task LogAsync(Exception exception) => LogAsync(new LogInfo(LogLevel.Error, string.Empty, exception.Message), exception);
public Task LogAsync(LogInfo logInfo) => LogAsync(logInfo, null);
public Task LogAsync(LogInfo logInfo, Exception exception)
{
var payload = logParser.Parse(logInfo, exception, ParseFormat.Json);
return SaveToDatabaseAsync(payload);
}
}
Parser Example
var parser = new LogParser();
var info = new LogInfo(LogLevel.Error, "Orders", "Unable to process order", traceId: "trace-123");
var html = parser.Parse(info, new InvalidOperationException("Boom"), ParseFormat.Html);
var json = parser.Parse(info, ParseFormat.Json);
Expected Result
When this package is doing its job:
application code emits one consistent logging payload model,
exception formatting is handled centrally, and
sink changes do not require broad changes to calling code.
Next Step
Read Logging Setup Workflow for the quickest path to a useful file-based logger.
Read Logger File if disk logging is the first sink.
Compare Logger Mail and Logger Web if the delivery target is operational alerting or remote transport.
Notes
LogInfo.ToString()produces a tab-separated representation, but the parser is the richer integration point.The base package does not write anywhere by itself; sink packages provide the actual transport.
If you need a custom sink, implement
ILoggerand optionally reuseILogParser.