public void Writes_Blank_Line_To_File() { using (var logger = new SimpleFileLogger(FileMocks.FileThatDoesNotExist())) { logger.WriteLine(); } Assert.That( File.ReadAllLines(FileMocks.FileThatDoesNotExist()).Length, Is.EqualTo(2) ); }
public void Writes_Simple_Message_To_File() { string message = "This is a log message"; using (var logger = new SimpleFileLogger(FileMocks.FileThatDoesNotExist())) { logger.WriteLine(message); } Assert.That( File.ReadAllText(FileMocks.FileThatDoesNotExist()), Is.StringContaining(message) ); }
public void Writes_Format_Message_To_File() { string format = "This is a log format with 2 params {0} {1}"; string param1 = "param1"; string param2 = "param2"; using (var logger = new SimpleFileLogger(FileMocks.FileThatDoesNotExist())) { logger.WriteLine(format, param1, param2); } Assert.That( File.ReadAllText(FileMocks.FileThatDoesNotExist()), Is.StringContaining(param1).And.StringContaining(param2) ); }
private static async Task Main(string[] args) { List <Account> accounts = new List <Account>(); ISimpleLogger logger; #if DEBUG logger = new SimpleConsoleLogger(); #else logger = new SimpleFileLogger(AppContext.BaseDirectory); #endif try { var builder = new ConfigurationBuilder() .SetBasePath(AppContext.BaseDirectory) .AddJsonFile("appsettings.json"); IConfigurationRoot configuration = builder.Build(); configuration.GetSection("accounts").Bind(accounts); using (var service = new VkCelebrationSchedulerService(accounts, logger)) { #if DEBUG await service.RunAsConsole(args); #else ServiceBase.Run(service); #endif } } catch (Exception ex) { logger.WriteException(ex); logger.WriteLine("====================================================="); } finally { Console.WriteLine("Press any key to exit..."); Console.ReadKey(); } }