static void Main() { ILayout simpleLayout = new SimpleLayout(); IAppender consoleAppender = new ConsoleAppender(simpleLayout); string filePath = "log.txt"; IAppender fileAppender = new FileAppender(filePath, simpleLayout); ILogger logger = new Logger(consoleAppender, fileAppender); logger.Error("Error parsing JSON."); logger.Info(string.Format("User {0} successfully registered.", "Pesho")); logger.Warn("Warning - missing files."); Console.WriteLine(); var xmlLayout = new XMLLayout(); consoleAppender.Layout = xmlLayout; logger.Fatal("mscorlib.dll does not respond"); logger.Critical("No connection string found in App.config"); Console.WriteLine(); consoleAppender.Layout = simpleLayout; logger.ReportLevel = ReportLevel.Critical; logger.Info("Everything seems fine"); logger.Warn("Warning: ping is too high - disconnect imminent"); logger.Error("Error parsing request"); logger.Critical("No connection string found in App.config"); logger.Fatal("mscorlib.dll does not respond"); }
static void Main() { var simpleLayout = new SimpleLayout(); var consoleAppender = new ConsoleAppender(simpleLayout); consoleAppender.ReportLevelThreshold = ReportLevel.Error; var logger = new Logger(consoleAppender); logger.Error("Error parsing JSON."); logger.Info(string.Format("User {0} successfully registered.", "Pesho")); logger.Info("Everything seems fine"); logger.Warning("Warning: ping is too high - disconnect imminent"); logger.Error("Error parsing request"); logger.Critical("No connection string found in App.config"); logger.Fatal("mscorlib.dll does not respond"); var xmlLayout = new XmlLayout(); var consoleAppender2 = new ConsoleAppender(xmlLayout); var logger2 = new Logger(consoleAppender2); logger2.Fatal("mscorlib.dll does not respond"); logger2.Critical("No connection string found in App.config"); var fileAppender = new FileAppender(simpleLayout); fileAppender.File = "log.txt"; var logger3 = new Logger(fileAppender); logger3.Warning("Warning - missing files.."); fileAppender.Close(); }
static void Main() { //ILayout xmLayout = new XmlLayout(); //FileAppender fileAppender = // new FileAppender(xmLayout); //ILogger logger = new Logger(fileAppender); //fileAppender.File = "log.txt"; //fileAppender.ReportLevel = ReportLevel.Error; ILayout simpleLayout = new SimpleLayout(); ConsoleAppender consoleAppender = new ConsoleAppender(simpleLayout); ILogger logger = new Logger(consoleAppender); consoleAppender.ReportLevel = ReportLevel.Error; try { logger.Info("Everything seems fine"); logger.Warn("Warning: ping is too high - disconnect imminent"); logger.Error("Error parsing request"); logger.Critical("No connection string found in App.config"); logger.Fatal("mscorlib.dll does not respond"); } catch (ArgumentException ex) { Console.WriteLine(ex.Message); } }
static void Main(string[] args) { ILayout simpleLayout = new SimpleLayout(); IAppender consoleAppender = new ConsoleAppender(simpleLayout); var fileAppender = new FileAppender(simpleLayout); fileAppender.File = "../../log.txt"; var logger = new Logger(consoleAppender, fileAppender); logger.Error("Error parsing JSON."); logger.Info(string.Format("User {0} successfully registered.", "Pesho")); logger.Warn("Warning - missing files."); var xmlLayout = new XmlLayout(); consoleAppender = new ConsoleAppender(xmlLayout); logger = new Logger(consoleAppender); logger.Fatal("mscorlib.dll does not respond"); logger.Critical("No connection string found in App.config"); consoleAppender = new ConsoleAppender(simpleLayout); consoleAppender.ReportLevel = ReportLevel.Error; logger = new Logger(consoleAppender); logger.Info("Everything seems fine"); logger.Warn("Warning: ping is too high - disconnect imminent"); logger.Error("Error parsing request"); logger.Critical("No connection string found in App.config"); logger.Fatal("mscorlib.dll does not respond"); }
public void Extensibility() { var xmlLayout = new XmlLayout(); var consoleAppender = new ConsoleAppender(xmlLayout); var logger = new Logger.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"); }
static void Main(string[] args) { var formatter = new XmlFormatter(); var appender = new ConsoleAppender(formatter); var logger = new Logger(appender); logger.Info("This is app"); logger.Error("Cannot be empty!"); logger.Critical("You are illigle"); }
public static void Main() { var simpleLayout = new SimpleLayout(); var consoleAppender = new ConsoleAppender(simpleLayout); consoleAppender.ReportLevel = ReportLevel.Error; var logger = new Logger(consoleAppender); logger.Info("Everything seems fine"); logger.Warn("Warning: ping is too high - disconnect imminent"); logger.Error("Error parsing request"); logger.Critical("No connection string found in App.config"); logger.Fatal("mscorlib.dll does not respond"); }
public void ReportThreshold() { var simpleLayout = new SimpleLayout(); var consoleAppender = new ConsoleAppender(simpleLayout); consoleAppender.ReportLevel = ReportLevel.Error; var logger = new Logger.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"); }
public static void Main() { try { var simpleLayout = new SimpleLayout(); var xmlLayout = new XmlLayout(); IAppender consoleAppender = new ConsoleAppender(simpleLayout); IAppender fileAppender = new FileAppender(simpleLayout); fileAppender.File = "../../log.txt"; IAppender fileAppenderXml = new FileAppender(xmlLayout); fileAppenderXml.File = "../../log.xml"; ILogger logger = new Logger(consoleAppender, fileAppender, fileAppenderXml); // add in logs logger.Error("Error parsing JSON."); logger.Info(string.Format("User {0} successfully registered.", "Pesho")); logger.Warn("Warn - missing files."); logger.Fatal("mscorlib.dll does not respond"); logger.Critical("No connection string found in App.config"); logger.Info("Everything seems fine"); logger.Warn("Warning: ping is too high - disconnect imminent"); logger.Error("Error parsing request"); logger.Critical("No connection string found in App.config"); logger.Fatal("mscorlib.dll does not respond"); } catch (ArgumentException ex) { Console.WriteLine(ex.Message); } Console.WriteLine(); }
static void Main() { IFormatter formatter = new JsonFormatter(); FileAppender appender = new FileAppender("../../file.txt", formatter); Logger.Logger logger = new Logger.Logger(appender); int a = 5; try { logger.Critical("a cannot be 5"); logger.Warn("Be carful for that 5!"); } finally { appender.Close(); } }
public static void Main() { var simpleLayout = new SimpleLayout(); var jsonLayout = new JsonLayout(); // var myLayout = new SoftUniLayout(); var consoleAppender = new ConsoleAppender(simpleLayout); consoleAppender.ReportLevel = ReportLevel.Error; consoleAppender.ReportLevel = ReportLevel.Error; var fileAppender = new FileAppendder(jsonLayout, "../../Log.txt"); fileAppender.ReportLevel = ReportLevel.Error; var logger = new Logger(consoleAppender, fileAppender); logger.Error("Error parsing JSON."); logger.Warning("User John successfully registered"); logger.Info("Everything seems fine"); logger.Warning("Warning: ping is too high - disconnect imminent"); logger.Error("Error parsing request"); logger.Critical("No connection string found in App.config"); logger.Fatal("mscorlib.dll does not respond"); fileAppender.Close(); }
public void Act(int countOfAppenders) { IAppender[] appenders = new IAppender[countOfAppenders]; for (int i = 0; i < countOfAppenders; i++) { var input = Console.ReadLine().Split(); ILayout layout = null; switch (input[1]) { case nameof(SimpleLayout): layout = new SimpleLayout(); break; case nameof(XmlLayout): layout = new XmlLayout(); break; default: throw new ArgumentException(); } IAppender appender = null; switch (input[0]) { case nameof(ConsoleAppender): appender = new ConsoleAppender(layout); break; case nameof(FileAppender): appender = new FileAppender(layout); ((FileAppender)appender).File = new LogFile(); break; } if (input.Length == 3) { ReportLevel level = (ReportLevel)Enum.Parse(typeof(ReportLevel), input[2]); appender.ReportLevel = level; } appenders[i] = appender; } var logger = new Logger(appenders); string command; while ((command = Console.ReadLine()) != "END") { var input = command.Split('|'); string time = input[1]; string message = input[2]; ReportLevel level = (ReportLevel)Enum.Parse(typeof(ReportLevel), input[0]); switch (level) { case ReportLevel.CRITICAL: logger.Critical(time, message); break; case ReportLevel.ERROR: logger.Error(time, message); break; case ReportLevel.FATAL: logger.Fatal(time, message); break; case ReportLevel.INFO: logger.Info(time, message); break; case ReportLevel.WARNING: logger.Warn(time, message); break; } } Console.WriteLine(logger); }