January 2017
Intermediate to advanced
314 pages
6h 42m
English
A simple test harness for the logging library is given next. The program accepts a command-line parameter, which is the log target (NET | FILE | DB). We create the appropriate logging strategy classes using the factory method pattern.
class Program
{
private static bool Table(LogStrategy ls)
{
int a = 10;
int b = 1;
while (b < 100)
{
ls.Log("Table", a.ToString() + " * " +
b.ToString(), "=" +(a * b).ToString());
b++;
}
return true;
}
static void Main(string[] args)
{
if (args.Length != 1)
{
return;
}
string loggertype=args[0];
LogStrategy lf = LoggerFactory.CreateLogger(loggertype);
Table(lf);
}
}
The following UML diagram illustrates the key set of patterns in action for the logging API:
Read now
Unlock full access