mirror of
https://github.com/Ellpeck/ExtremelySimpleLogger.git
synced 2024-11-22 01:53:29 +01:00
1.5 KiB
1.5 KiB
ExtremelySimpleLogger
A very simple logger for .NET programs.
To set up an extremely simple logger, add a reference to the NuGet package to your project file. Remember to change the VERSION
to the most recent one.
<ItemGroup>
<PackageReference Include="ExtremelySimpleLogger" Version="VERSION" />
</ItemGroup>
Next, you have to create an instance of the Logger
class:
var logger = new Logger {
Name = "My Logger",
Sinks = {
new FileSink("Log.txt", append: true),
new ConsoleSink()
}
};
Since there are multiple ways for logging data to be processed, the logger needs to receive a set of Sink
instances. By default, the following sinks are available:
FileSink
, which outputs logging data to a fileConsoleSink
, which outputs logging data to the default consoleDirectorySink
, which outputs logging data to a set of files and automatically manages how many old logs are keptStringSink
, which stores logging data in a string
There are multiple ways to easily log messages with your newly created logger:
// Logging info
logger.Log(LogLevel.Info, "Some information");
logger.Info("Some information, but shorter");
// Logging exceptions
try {
// some dangerous code
} catch (Exception e) {
logger.Error("An exception was thrown", e);
}
For more information, you can also check out the sample.