From dd62d3d2c17914aec4fbf89873f795a86d35b710 Mon Sep 17 00:00:00 2001 From: Ellpeck Date: Thu, 23 Jul 2020 13:45:43 +0200 Subject: [PATCH] expand the sample a bit --- README.md | 4 +++- Sample/Program.cs | 21 ++++++++++++++++----- 2 files changed, 19 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 597f9b2..42b559f 100644 --- a/README.md +++ b/README.md @@ -35,4 +35,6 @@ try { } catch (Exception e) { logger.Error("An exception was thrown", e); } -``` \ No newline at end of file +``` + +For more information, you can also check out [the sample](https://github.com/Ellpeck/ExtremelySimpleLogger/blob/master/Sample/Program.cs). \ No newline at end of file diff --git a/Sample/Program.cs b/Sample/Program.cs index 2524b47..f07a708 100644 --- a/Sample/Program.cs +++ b/Sample/Program.cs @@ -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 { + // 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."); }