Design Pattern Examples
Overview of object-oriented design patterns
Bridge_ConsoleLogger.cs
Go to the documentation of this file.
1
5
6using System;
7
9{
13 internal class ConsoleLogger : ILogger, IDisposable
14 {
15 private bool _disposed;
16
20 private ConsoleLogger()
21 {
22 }
23
24
30 private void _WriteLine(string logLevel, string msg)
31 {
32 string output = LoggerHelpers.FormatLogLine(logLevel, msg);
33 Console.WriteLine(output);
34 }
35
36
37
38 #region ILogger Members
39
40 void ILogger.LogTrace(string msg)
41 {
42 _WriteLine("TRACE", msg);
43 }
44
45 void ILogger.LogInfo(string msg)
46 {
47 _WriteLine("INFO ", msg);
48 }
49
50 void ILogger.LogError(string msg)
51 {
52 _WriteLine("ERROR", msg);
53 }
54
55 #endregion
56
57 #region IDisposable Members
58
62 void IDisposable.Dispose()
63 {
64 if (!_disposed)
65 {
66 _disposed = true;
67 }
68 }
69
70 #endregion
71
72
78 {
79 return new ConsoleLogger();
80 }
81 }
82}
Represents a logger that writes to the console window.
static ILogger CreateConsoleLogger()
Create an instance of a console logger, where logging goes to the console.
void _WriteLine(string logLevel, string msg)
Send a formatted line to the console.
static string FormatLogLine(string logLevel, string msg)
Format a line for logging, including time stamp.
Represents an implementation of a logger object as call from the Logger class.
void LogError(string msg)
Log error messages to the configured output.
void LogTrace(string msg)
Log trace messages to the configured output.
void LogInfo(string msg)
Log informational messages to the configured output.
The namespace containing all Design Pattern Examples implemented in C#.