VersaTul.Logger
1.0.8
Prefix Reserved
dotnet add package VersaTul.Logger --version 1.0.8
NuGet\Install-Package VersaTul.Logger -Version 1.0.8
<PackageReference Include="VersaTul.Logger" Version="1.0.8" />
paket add VersaTul.Logger --version 1.0.8
#r "nuget: VersaTul.Logger, 1.0.8"
// Install VersaTul.Logger as a Cake Addin #addin nuget:?package=VersaTul.Logger&version=1.0.8 // Install VersaTul.Logger as a Cake Tool #tool nuget:?package=VersaTul.Logger&version=1.0.8
VersaTul Logger
VersaTul Logger is a project that provides common functionality for different types of loggers, such as FileLogger, MailLogger, and WebLogger. It also provides interfaces to ensure consistency across all logger apps.
Installation
You can install VersaTul Logger using NuGet:
PM> NuGet\Install-Package VersaTul.Logger -Version latest
Usage
To use VersaTul Logger, you need to implement the ILogger
interface, which represents the functionality provided by a logger. You also need to implement the ILogParser
interface, which represents the parsing functionality to use for parsing logged data.
Here is an example of how to create and use a DatabaseLogger
class that implements both interfaces:
// Create a project specific interface
public interface IDatabaseLogger : ILogger
{
// project specific methods can be added here...
}
// Implementing interface
public class DatabaseLogger: IDatabaseLogger
{
private readonly ILogParser logParser;
public DatabaseLogger(ILogParser logParser)
{
this.logParser = logParser;
}
// interface methods...
public void Log(LogInfo logInfo) => LogAsync(logInfo)
.GetAwaiter()
.GetResult();
public void Log(Exception exception) => LogAsync(exception)
.GetAwaiter()
.GetResult();
public void Log(LogInfo logInfo, Exception exception) => LogAsync(logInfo, exception)
.GetAwaiter()
.GetResult();
public async Task LogAsync(Exception exception) => await LogAsync(new LogInfo(LogLevel.Error, string.Empty, exception.Message), exception);
public async Task LogAsync(LogInfo logInfo) => await LogAsync(logInfo, null);
public async Task LogAsync(LogInfo logInfo, Exception exception)
{
var message = logParser.Parse(logInfo, exception, ParseFormat.Tab);
// send message to database here...
}
}
// Configure the container using AutoFac Module
public class AppModule : Module
{
protected override void Load(ContainerBuilder builder)
{
// Registering logger to container
builder
.RegisterType<DatabaseLogger>()
.As<IDatabaseLogger>()
.As<ILogger>()
.SingleInstance();
}
}
// Usage catching and logging exceptions...
public abstract class BaseController : Controller
{
private readonly ILogger logger;
protected BaseController(ILogger logger)
{
this.logger = logger;
}
protected IActionResult FaultHandler(Func<IActionResult> codeToExecute)
{
try
{
return codeToExecute();
}
catch (Exception ex)
{
logger.Log(ex);
return BadRequest();
}
}
}
License
This project is licensed under the MIT License. See the LICENSE file for details.
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net8.0 is compatible. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. |
-
net8.0
- Newtonsoft.Json (>= 13.0.3)
NuGet packages (4)
Showing the top 4 NuGet packages that depend on VersaTul.Logger:
Package | Downloads |
---|---|
VersaTul.Data.Sql
The VersaTul Data Sql project provides the ability to quickly create database access objects, usable on any suppporting SQL databases. This project is built on top of the System.Data.Common namespace and provides the functionality to quickly call stored procedures or plain text sql queries, then map the result into data objects using the provided helper methods. |
|
VersaTul.Logger.File
The VersaTul Logger File project provides the functionality needed to performing logging in a flat file. This project implements the ILogger interface from the VersaTul Logger project. |
|
VersaTul.Logger.Web
The VersaTul Logger Web project provides the functionality needed to performing logging to a web address or end point. This project implements the ILogger interface from the VersaTul Logger project. |
|
VersaTul.Logger.Mail
The VersaTul Logger Mail project provides the functionality needed to performing logging to a email address or addresses. This project implements the ILogger interface from the VersaTul Logger project. There is also a dependency on the VersaTul Mailer project, which is used to send emails. |
GitHub repositories
This package is not used by any popular GitHub repositories.