static ILogger InitializeLogger() { ICollection <IAppender> appenders = new List <IAppender>(); LayoutFactory layoutFactory = new LayoutFactory(); AppenderFactory appenderFactory = new AppenderFactory(layoutFactory); int appenderCount = int.Parse(Console.ReadLine()); for (int i = 0; i < appenderCount; i++) { string[] args = Console.ReadLine().Split(); string appenderType = args[0]; string layoutType = args[1]; string errorLevel = "INFO"; if (args.Length == 3) { errorLevel = args[2]; } IAppender appender = appenderFactory.CreateAppender(appenderType, errorLevel, layoutType); appenders.Add(appender); } ILogger logger = new Models.Logger(appenders); return(logger); }
static void Main() { var simpleLayout = new SimpleLayout(); var consoleAppender = new ConsoleAppender(simpleLayout); var fileAppender = new FileAppender(simpleLayout); fileAppender.LogFile = "log.txt"; var errorLog = new Log(new Level("Error"), "Error parsing JSON."); var infoLog = new Log(new Level("Info"), string.Format("User {0} successfully registered.", "Pesho")); var warnLog = new Log(new Level("Warning"), "Warning - missing files."); var logger = new Models.Logger(new List<IAppender> { consoleAppender, fileAppender }); logger.AppendLog(errorLog); logger.AppendLog(infoLog); logger.AppendLog(warnLog); //xml Logger var xmlLayout = new XmlLayout(); var consoleXmlAppender = new ConsoleAppender(xmlLayout); var xmlLogger = new Models.Logger(new List<IAppender>{consoleXmlAppender}); var fatalLog = new Log(new Level("Fatal"), "mscorlib.dll does not respond"); var criticalLog = new Log(new Level("Critical"), "No connection string found in App.config"); xmlLogger.AppendLog(fatalLog); xmlLogger.AppendLog(criticalLog); }
static void Main(string[] args) { ILayout layout = new SimpleLayout(); IAppender appender = new ConsoleAppender(layout, ErrorLevel.INFO); ILogger logger = new Models.Logger(new IAppender[] { appender }); IError error = new Error(DateTime.Now, "Critical error!", ErrorLevel.CRITICAL); logger.Log(error); Console.WriteLine(logger.Log(error)); }
static void Main(string[] args) { int appendersCount = int.Parse(Console.ReadLine()); ICollection <IAppender> appenders = new List <IAppender>(); AppenderFactory appenderFactory = new AppenderFactory(); ILogger logger = new Models.Logger(appenders); ReadAppendersData(appendersCount, appenders, appenderFactory); Engine engine = new Engine(logger); engine.Run(); }
static void Main() { var simpleLayout = new SimpleLayout(); var consoleAppender = new ConsoleAppender(simpleLayout); var fileAppender = new FileAppender(simpleLayout); fileAppender.File = "../../log.txt"; var logger = new Models.Logger(consoleAppender, fileAppender); logger.Error("Error parsing JSON."); logger.Info(string.Format("User {0} successfully registered.", "Pesho")); logger.Warn("Warning - missing files."); }
static void Main() { var numberOfApenders = int.Parse(Console.ReadLine()); ICollection <IAppender> appenders = new List <IAppender>(); AppenderFactory apenderFactory = new AppenderFactory(); ReadAppendersData(numberOfApenders, appenders, apenderFactory); ILogger logger = new Models.Logger(appenders); var engine = new Engine(logger); engine.Run(); }
public static void Main() { //ILayout simpleLayout = new SimpleLayout(); //IAppender consoleAppender = new ConsoleAppender(simpleLayout); //ILogger logger = new Models.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."); // ********************************************** //ILayout simpleLayout = new SimpleLayout(); //IAppender consoleAppender = new ConsoleAppender(simpleLayout); //IFile file = new LogFile(); ////file.Write(simpleLayout, ErrorFactory.Create("Fatal", //// DateTime.Now.ToString(ProjectConstants.DATETIME_FORMAT,CultureInfo.InvariantCulture), //// "Super fatality happened!")); //IAppender fileAppender = new FileAppender(simpleLayout, file); //ILogger logger = new Models.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."); // ********************************************** //ILayout xmlLayout = new XmlLayout(); //ILayout simpleLayout = new SimpleLayout(); //IAppender consoleAppender = new ConsoleAppender(simpleLayout); //IFile file = new LogFile(); //IAppender fileAppender = new FileAppender(xmlLayout, file); //ILogger logger = new Models.Logger(consoleAppender, fileAppender); //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"); // ********************************************** //var simpleLayout = new SimpleLayout(); //var consoleAppender = new ConsoleAppender(simpleLayout); //consoleAppender.ReportLevel = Level.Error; //var logger = new Models.Logger(consoleAppender); //logger.Info("3/31/2015 5:33:07 PM", "Everything seems fine"); //logger.Warning("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"); // ********************************************** //var layout = new SimpleLayout(); //var xmlLayout = new XmlLayout(); //var file = new LogFile(); //var fileAppender = new FileAppender(layout, file); //var logger = new Models.Logger(fileAppender); //logger.Error("3/31/2015 5:33:07 PM", "Error parsing request"); //Console.WriteLine(file.Size); // ********************************************** int appendersCount = int.Parse(Console.ReadLine()); IAppender[] appenders = new IAppender[appendersCount]; for (int i = 0; i < appendersCount; i++) { string[] appenderArgs = Console.ReadLine().Split(' ', StringSplitOptions.RemoveEmptyEntries); switch (appenderArgs.Length) { // "<appender type> <layout type> <REPORT LEVEL>" case 2: appenders[i] = AppenderFactory.Create(appenderArgs[1], appenderArgs[0]); break; case 3: appenders[i] = AppenderFactory.Create(appenderArgs[1], appenderArgs[0], appenderArgs[2]); break; } } var logger = new Models.Logger(appenders); CommandInterpreter.Run(logger); Console.WriteLine(logger); }