mirror of
https://github.com/Ellpeck/ExtremelySimpleLogger.git
synced 2024-11-24 18:48:34 +01:00
expand the sample a bit
This commit is contained in:
parent
404dc0ca8d
commit
dd62d3d2c1
2 changed files with 19 additions and 6 deletions
|
@ -36,3 +36,5 @@ try {
|
||||||
logger.Error("An exception was thrown", e);
|
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).
|
|
@ -1,4 +1,5 @@
|
||||||
using System;
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using ExtremelySimpleLogger;
|
using ExtremelySimpleLogger;
|
||||||
|
|
||||||
|
@ -6,16 +7,24 @@ namespace Sample {
|
||||||
internal static class Program {
|
internal static class Program {
|
||||||
|
|
||||||
private static void Main() {
|
private static void Main() {
|
||||||
var logger = new Logger {
|
// When we have multiple loggers that output to the same file,
|
||||||
Name = "Example Logger",
|
// we can just reuse our sinks
|
||||||
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 FileSink("Log.txt", true) {MinimumLevel = LogLevel.Trace},
|
||||||
new ConsoleSink()
|
new ConsoleSink()
|
||||||
}
|
};
|
||||||
|
var logger = new Logger {
|
||||||
|
Name = "Example Logger",
|
||||||
|
Sinks = sinks
|
||||||
|
};
|
||||||
|
var otherLogger = new Logger {
|
||||||
|
Name = "Special Logger",
|
||||||
|
Sinks = sinks
|
||||||
};
|
};
|
||||||
logger.Info("Logger loaded.");
|
logger.Info("Logger loaded.");
|
||||||
logger.Info("Program starting.");
|
|
||||||
|
|
||||||
|
// Logging an exception
|
||||||
logger.Warn("Unsafe code follows!");
|
logger.Warn("Unsafe code follows!");
|
||||||
try {
|
try {
|
||||||
File.OpenRead("does/not/exist");
|
File.OpenRead("does/not/exist");
|
||||||
|
@ -23,6 +32,8 @@ namespace Sample {
|
||||||
logger.Error("An exception was thrown!", e);
|
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.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.");
|
logger.Log(LogLevel.Info, "The program finished.");
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue