| | 1 | | using NtpServiceLibrary; |
| | 2 | |
|
| | 3 | | [assembly: System.Runtime.CompilerServices.InternalsVisibleTo("NtpUnitTests")] |
| | 4 | |
|
| | 5 | | namespace NtpServiceConsole |
| | 6 | | { |
| | 7 | | /// <summary> |
| | 8 | | /// Provides a simple logger implementation that writes log messages to the console. |
| | 9 | | /// </summary> |
| | 10 | | internal class ConsoleLogger : ILogger |
| | 11 | | { |
| | 12 | | /// <summary> |
| | 13 | | /// The name of the service to include in log messages. |
| | 14 | | /// </summary> |
| | 15 | | readonly string _serviceName; |
| | 16 | |
|
| | 17 | | /// <summary> |
| | 18 | | /// Initializes a new instance of the <see cref="ConsoleLogger"/> class. |
| | 19 | | /// </summary> |
| | 20 | | /// <param name="serviceName">The name of the service to prefix log messages with.</param> |
| 6 | 21 | | public ConsoleLogger(string serviceName) |
| 6 | 22 | | { |
| 6 | 23 | | _serviceName = serviceName; |
| 6 | 24 | | } |
| | 25 | |
|
| | 26 | | /// <summary> |
| | 27 | | /// Initializes the logger. No action is required for the console logger. |
| | 28 | | /// </summary> |
| | 29 | | public void Start() |
| 2 | 30 | | { |
| 2 | 31 | | } |
| | 32 | |
|
| | 33 | | /// <summary> |
| | 34 | | /// Writes a message to the console log. |
| | 35 | | /// </summary> |
| | 36 | | /// <param name="message">The message to log.</param> |
| | 37 | | public void Write(string message) |
| 2 | 38 | | { |
| 2 | 39 | | Console.WriteLine(string.Format("{0}: {1}", _serviceName, message)); |
| 2 | 40 | | } |
| | 41 | |
|
| | 42 | | /// <summary> |
| | 43 | | /// Writes a formatted message to the console log. |
| | 44 | | /// </summary> |
| | 45 | | /// <param name="format">A composite format string.</param> |
| | 46 | | /// <param name="parameters">An array of objects to format.</param> |
| | 47 | | public void Write(string format, params object[] parameters) |
| 2 | 48 | | { |
| 2 | 49 | | Console.WriteLine(string.Format("{0}: {1}", _serviceName, string.Format(format, parameters))); |
| 2 | 50 | | } |
| | 51 | | } |
| | 52 | | } |