VersaTul.Logger
1.0.9
Prefix Reserved
See the version list below for details.
dotnet add package VersaTul.Logger --version 1.0.9
NuGet\Install-Package VersaTul.Logger -Version 1.0.9
<PackageReference Include="VersaTul.Logger" Version="1.0.9" />
paket add VersaTul.Logger --version 1.0.9
#r "nuget: VersaTul.Logger, 1.0.9"
// Install VersaTul.Logger as a Cake Addin #addin nuget:?package=VersaTul.Logger&version=1.0.9 // Install VersaTul.Logger as a Cake Tool #tool nuget:?package=VersaTul.Logger&version=1.0.9
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 | net6.0 is compatible. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 is compatible. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. 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. net9.0 is compatible. |
-
net6.0
- Newtonsoft.Json (>= 13.0.3)
-
net7.0
- Newtonsoft.Json (>= 13.0.3)
-
net8.0
- Newtonsoft.Json (>= 13.0.3)
-
net9.0
- Newtonsoft.Json (>= 13.0.3)
NuGet packages (3)
Showing the top 3 NuGet packages that depend on VersaTul.Logger:
Package | Downloads |
---|---|
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.