static void Main(string[] args) { try { var loggerDataBase = new JobLogger(); loggerDataBase.AddFormatProvider(new DataBaseProvider(new Logger.exam.Logger.DataBaseEntry())); loggerDataBase.WriteError("example write error in database"); loggerDataBase.WriteMessage("example write message in database"); loggerDataBase.WriteWarning("example write warning in database"); var loggerFile = new JobLogger(); loggerFile.AddFormatProvider(new FileProvider(new Logger.exam.Logger.FileEntry())); loggerFile.WriteError("example write error in file"); loggerFile.WriteMessage("example write message in file"); loggerFile.WriteWarning("example write warning in file"); var loggerConsole = new JobLogger(); loggerConsole.AddFormatProvider(new ConsoleProvider(new Logger.exam.Logger.ConsoleEntry())); loggerConsole.WriteError("example write error in console"); loggerConsole.WriteMessage("example write message in console"); loggerConsole.WriteWarning("example write warning in console"); var loggerAllProvider = new JobLogger(); loggerAllProvider.AddFormatProvider(new ConsoleProvider(new Logger.exam.Logger.ConsoleEntry())); loggerAllProvider.AddFormatProvider(new FileProvider(new Logger.exam.Logger.FileEntry())); loggerAllProvider.AddFormatProvider(new DataBaseProvider(new Logger.exam.Logger.DataBaseEntry())); loggerAllProvider.WriteError("example write error in console, database and file"); loggerAllProvider.WriteMessage("example write message console, database and file"); loggerAllProvider.WriteWarning("example write warning console, database and file"); } catch (Exception ex) { Console.WriteLine(string.Format("Application Error :", ex.Message)); } }
public void WhenNotConfigureProviderAndYouTryToWriteErrorThenExceptionInvalidConfiguration() { var logger = new JobLogger(); var consoleEntry = new mockup.ConsoleEntryTest(); var message = "Message"; logger.WriteError(message); }
public void WhenHaveOneProblemWithEntryToWriteErrorThenExceptionCustomDefault() { var logger = new JobLogger(); var consoleEntry = new mockup.ConsoleEntryWithErrorTest(); logger.AddFormatProvider(new ConsoleProvider(consoleEntry)); var message = "Message"; logger.WriteError(message); }
public void WhenWriteErrorOnlyFileThenSaveError() { var logger = new JobLogger(); var entry = new mockup.FileEntryTest(); logger.AddFormatProvider(new FileProvider(entry)); var message = "Message"; logger.WriteError(message); var expectedMessage = string.Format("{0}: {1}", DateTime.Now.ToShortDateString(), message); Assert.AreEqual(expectedMessage, entry.GetResults()[0].Message); Assert.AreEqual(Logger.exam.Common.Enums.LogType.Error, entry.GetResults()[0].LogType); }
public void WhenProviderIsDataBaseThenSaveDataBase() { var logger = new JobLogger(); var entryDataBase = new mockup.DataBaseEntryTest(); logger.AddFormatProvider(new DataBaseProvider(entryDataBase)); var message = "Message error save in DataBase"; logger.WriteError(message); var expectedMessage = message; Assert.AreEqual(expectedMessage, entryDataBase.GetResults()[0].Message); Assert.AreEqual(Logger.exam.Common.Enums.LogType.Error, entryDataBase.GetResults()[0].LogType); }
public void WhenNotConfigureProviderThenNoHasProvider() { var logger = new JobLogger(); Assert.IsFalse(logger.HasProvider()); }