Toms.Logger
1.0.0
See the version list below for details.
dotnet add package Toms.Logger --version 1.0.0
NuGet\Install-Package Toms.Logger -Version 1.0.0
<PackageReference Include="Toms.Logger" Version="1.0.0" />
paket add Toms.Logger --version 1.0.0
#r "nuget: Toms.Logger, 1.0.0"
// Install Toms.Logger as a Cake Addin #addin nuget:?package=Toms.Logger&version=1.0.0 // Install Toms.Logger as a Cake Tool #tool nuget:?package=Toms.Logger&version=1.0.0
Toms Logger
This is a simple logging library that allows you to log messages with different levels of severity. It also supports logging method calls and exits, and saving logs to a file.
Installation
You can install the Toms Logger library via NuGet:
PM> Install-Package Toms.Logger
Usage
Logger Class
The Logger
class is the main class of the library. You can create an instance of it and use its methods to log messages.
var logger = new Logger();
The Logger
class has methods for logging messages at different levels of severity:
Debug
: Logs a debug message.Info
: Logs an informational message.Warning
: Logs a warning message.Error
: Logs an error message.
logger.Debug("This is a debug message");
logger.Info("This is an informational message");
logger.Warning("This is a warning message");
logger.Error("This is an error message");
You can also save the logs to a file:
logger.SaveToFile("log.txt");
LogCall and LogExit Attributes
The LogCall
and LogExit
attributes can be used to log method calls and exits. They are always Debug
.
[LogCall]
[LogExit]
public void MyMethodWithAttr() {
logger.Info("Inside the method");
}
This will log a message both when the method is called and when it exits.
Configuration
The LogConfig
class is used to configure the logger. You can set the display level, whether to use full class names, and whether to save logs to a file.
var conf = LogConfigBuilder.Default
.SetDisplayLevel(LogLevel.Debug)
.SetUseFullClassName(false)
.SaveToFile(false)
.Build();
Example
Here's an example of how to use the logger:
class MyClass
{
Logger Logger {get;}
public MyClass(Logger logger)
{
Logger = logger;
}
public void MyMethod() {
Logger.Debug("First message");
Logger.Info("2nd text");
Logger.Warning("This is a warning message");
Logger.Error("Error message");
}
[LogCall]
[LogExit]
public void MyMethodWithAttr() {
Logger.Info("Inside the method");
}
}
var conf = LogConfigBuilder.Default
.SetDisplayLevel(LogLevel.Debug)
.SetUseFullClassName(false)
.SaveToFile(false)
.Build();
var l = new Logger(conf);
var myInstance = new MyClass(l);
myInstance.MyMethod();
myInstance.MyMethodWithAttr();
This will log the messages from MyMethod
and the calls and exits of MyMethodWithAttr
.
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
- AspectInjector (>= 2.8.2)
- Spectre.Console (>= 0.48.0)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.