public static void Main() { var appendersCount = int.Parse(Console.ReadLine()); IAppender[] appenders = new IAppender[appendersCount]; for (int i = 0; i < appendersCount; i++) { var appenderInfo = Console.ReadLine().Split(); ILayout currentLayout = LayoutFactory.GetInstance(appenderInfo[1]); var currAppender = AppenderFactory.GetAppender(appenderInfo[0], currentLayout); if (appenderInfo.Length > 2) { string enumName = CultureInfo.CurrentCulture.TextInfo.ToTitleCase(appenderInfo[2].ToLower()); currAppender.ReportLevel = (ReportLevel)Enum.Parse(typeof(ReportLevel), enumName); } appenders[i] = currAppender; } var myLogger = new Entities.Logger(appenders); string input; while ((input = Console.ReadLine()) != "END") { var tokens = input.Split('|'); var methodName = CultureInfo.CurrentCulture.TextInfo.ToTitleCase(tokens[0].ToLower()); MethodInfo currentMethod = typeof(Entities.Logger).GetMethod(methodName); currentMethod.Invoke(myLogger, new object[] { tokens[1], tokens[2] }); } Console.WriteLine(myLogger); }
static void Main(string[] args) { int appenderCount = int.Parse(Console.ReadLine()); IAppender[] appenders = new IAppender[appenderCount]; for (int i = 0; i < appenderCount; i++) { string[] appenderInfo = Console.ReadLine().Split(); ILayout currentLayout = LayoutFactory.GetInstance(appenderInfo[1]); IAppender currentAppender = AppenderFactory.GetInstance(appenderInfo[0], currentLayout); if (appenderInfo.Length > 2) { string enumName = CultureInfo.CurrentCulture.TextInfo.ToTitleCase(appenderInfo[2].ToLower()); currentAppender.ReportLevel = (ReportLevel)Enum.Parse(typeof(ReportLevel), enumName); } appenders[i] = currentAppender; } ILogger logger = new Log(appenders); string input; while ((input = Console.ReadLine()) != "END") { string[] messageParts = input.Split('|'); string methodName = CultureInfo.CurrentCulture.TextInfo.ToTitleCase(messageParts[0].ToLower()); MethodInfo currentMethod = typeof(Log).GetMethod(methodName); currentMethod.Invoke(logger, new string[] { messageParts[1], messageParts[2] }); } Console.WriteLine(logger); Console.ReadLine(); }
internal void GetAppendersFromConsole() { var numberOfAppenders = int.Parse(Console.ReadLine()); appenders = new Appender[numberOfAppenders]; for (int i = 0; i < numberOfAppenders; i++) { var input = Console.ReadLine().Split(); ILayout currentLayout = layoutFactory.GetInstance(input[1]); Appender currentAppender = appenderFactory.GetAppender(input[0], currentLayout); if (input.Length > 2) { string enumName = CultureInfo.CurrentCulture.TextInfo.ToTitleCase(input[2].ToLower()); currentAppender.ReportLevel = (ReportLevel)Enum.Parse(typeof(ReportLevel), enumName); } this.appenders[i] = currentAppender; } }
public static void Main(string[] args) { //I-part //ILayout simpleLayout = new SimpleLayout(); //IAppender consoleAppender = new ConsoleAppender(simpleLayout); //ILogger logger = new Logger(consoleAppender); //logger.Error("3/26/2015 2:08:11 PM", "Error parsing JSON."); //logger.Info("3/26/2015 2:08:11 PM", "User Pesho successfully registered."); //II-part //var simpleLayout = new SimpleLayout(); //var consoleAppender = new ConsoleAppender(simpleLayout); //var file = new LogFile(); //var fileAppender = new FileAppender(simpleLayout); //fileAppender.File = file; //var logger = new Logger(consoleAppender, fileAppender); //logger.Error("3/26/2015 2:08:11 PM", "Error parsing JSON."); //logger.Info("3/26/2015 2:08:11 PM", "User Pesho successfully registered."); //III-part //var xmlLayout = new XmlLayout(); //var consoleAppender = new ConsoleAppender(xmlLayout); //var logger = new Logger(consoleAppender); //logger.Fatal("3/31/2015 5:23:54 PM", "mscorlib.dll does not respond"); //logger.Critical("3/31/2015 5:23:54 PM", "No connection string found in App.config"); //IV-part //var simpleLayout = new SimpleLayout(); //var consoleAppender = new ConsoleAppender(simpleLayout); //consoleAppender.ReportLevel = ReportLevel.Error; //var logger = new Logger(consoleAppender); //logger.Info("3/31/2015 5:33:07 PM", "Everything seems fine"); //logger.Warn("3/31/2015 5:33:07 PM", "Warning: ping is too high - disconnect imminent"); //logger.Error("3/31/2015 5:33:07 PM", "Error parsing request"); //logger.Critical("3/31/2015 5:33:07 PM", "No connection string found in App.config"); //logger.Fatal("3/31/2015 5:33:07 PM", "mscorlib.dll does not respond"); //V-part var appendersCount = int.Parse(Console.ReadLine()); IAppender[] appenders = new IAppender[appendersCount]; for (int i = 0; i < appendersCount; i++) { var appenderInfo = Console.ReadLine().Split(' '); ILayout currentLayout = LayoutFactory.GetInstance(appenderInfo[1]); IAppender currentAppender = AppenderFactory.GetAppender(appenderInfo[0], currentLayout); if (appenderInfo.Length > 2) { string enumName = CultureInfo.CurrentCulture.TextInfo.ToTitleCase(appenderInfo[2].ToLower()); currentAppender.ReportLevel = (ReportLevel)Enum.Parse(typeof(ReportLevel), enumName); } appenders[i] = currentAppender; } Logger myLogger = new Logger(appenders); string input; while ((input = Console.ReadLine()) != "END") { var tokens = input.Split('|'); var methodName = CultureInfo.CurrentCulture.TextInfo.ToTitleCase(tokens[0].ToLower()); MethodInfo currentMethod = typeof(Logger).GetMethod(methodName); currentMethod.Invoke(myLogger, new object[] { tokens[1], tokens[2] }); } Console.WriteLine(myLogger); }