expand the sample a bit

This commit is contained in:
Ellpeck 2020-07-23 13:45:43 +02:00
parent 404dc0ca8d
commit dd62d3d2c1
2 changed files with 19 additions and 6 deletions

View file

@ -36,3 +36,5 @@ try {
logger.Error("An exception was thrown", e);
}
```
For more information, you can also check out [the sample](https://github.com/Ellpeck/ExtremelySimpleLogger/blob/master/Sample/Program.cs).

View file

@ -1,4 +1,5 @@
using System;
using System.Collections.Generic;
using System.IO;
using ExtremelySimpleLogger;
@ -6,16 +7,24 @@ namespace Sample {
internal static class Program {
private static void Main() {
// When we have multiple loggers that output to the same file,
// we can just reuse our sinks
var sinks = new List<Sink> {
// We want to log messages of every log level, so we set the minimum level to Trace
new FileSink("Log.txt", true) {MinimumLevel = LogLevel.Trace},
new ConsoleSink()
};
var logger = new Logger {
Name = "Example Logger",
Sinks = {
new FileSink("Log.txt", true) {MinimumLevel = LogLevel.Trace},
new ConsoleSink()
}
Sinks = sinks
};
var otherLogger = new Logger {
Name = "Special Logger",
Sinks = sinks
};
logger.Info("Logger loaded.");
logger.Info("Program starting.");
// Logging an exception
logger.Warn("Unsafe code follows!");
try {
File.OpenRead("does/not/exist");
@ -23,6 +32,8 @@ namespace Sample {
logger.Error("An exception was thrown!", e);
}
otherLogger.Info("This is a special message from the special logger!");
logger.Log(LogLevel.Trace, "This is a message that only the file sink will receive, since its minimum level is lower.");
logger.Log(LogLevel.Info, "The program finished.");
}