Design Pattern Examples
Overview of object-oriented design patterns
Bridge_Exercise.cs
Go to the documentation of this file.
1
5
6using System;
7
9{
20 internal class Bridge_Exercise
21 {
30 void _Bridge_Exercise_Demonstrate_Logging(Logger logger, string loggerType)
31 {
32 logger.LogTrace(String.Format("Starting log to {0} example", loggerType));
33 logger.LogInfo("An example of an informational line");
34 logger.LogError("An example of an error log entry");
35 logger.LogTrace(String.Format("Done with log to {0} example", loggerType));
36 }
37
41 // ! [Using Bridge in C#]
42 public void Run()
43 {
44 Console.WriteLine();
45 Console.WriteLine("Bridge Exercise");
46 using (Logger logger = new Logger(Logger.LoggerTypes.ToFile, "Bridge.log"))
47 {
48 Console.WriteLine(" Example of writing to a log file...");
50 }
51
52 using (Logger logger = new Logger(Logger.LoggerTypes.ToConsole))
53 {
54 Console.WriteLine(" Example of writing to the console...");
55 _Bridge_Exercise_Demonstrate_Logging(logger, "console");
56 }
57
58 using (Logger logger = new Logger(Logger.LoggerTypes.ToNull))
59 {
60 Console.WriteLine(" Example of writing to a Null object (no output)...");
61 // Note: The resulting log lines will not be shown anywhere.
63 }
64 Console.WriteLine(" Done.");
65 }
66 // ! [Using Bridge in C#]
67 }
68}
Example of using the Bridge Pattern in C#.
void _Bridge_Exercise_Demonstrate_Logging(Logger logger, string loggerType)
Helper function to show an example of writing to a logger.
void Run()
Executes the example for the Bridge Pattern in C#.
Represents the logger object to be used in the program.
void LogInfo(string message)
Log informational messages to the configured output.
LoggerTypes
A value passed to Logger.Logger() constructor to specify the type of logger to create.
void LogTrace(string message)
Log trace messages to the configured output.
void LogError(string message)
Log error messages to the configured output.
The namespace containing all Design Pattern Examples implemented in C#.