public void Constructor1SetsTimeoutToDefaultTimeoutWhenParameterIsNull() { var timeout = TimeSpan.FromMilliseconds(1234); var consoleLogProvider = new ConsoleLogProvider(timeout: null); consoleLogProvider.Timeout.Should().Be(ConsoleLogProvider.DefaultTimeout); }
static int Main(string[] args) { try { var appRootFolder = AppDomain.CurrentDomain.BaseDirectory; var logProvider = new ConsoleLogProvider(); var host = Host.Find(appRootFolder, logProvider); var configuration = host.RhetosRuntime.BuildConfiguration(logProvider, host.ConfigurationFolder, configurationBuilder => configurationBuilder.AddConfigurationManagerConfiguration()); LegacyUtilities.Initialize(configuration); string connectionString = SqlUtility.ConnectionString; Console.WriteLine("SQL connection: " + SqlUtility.SqlConnectionInfo(connectionString)); var sqlExecuter = GetSqlExecuterImplementation(connectionString); var databaseCleaner = new DatabaseCleaner(new ConsoleLogProvider(), sqlExecuter); databaseCleaner.DeleteAllMigrationData(); return(0); } catch (Exception ex) { Console.WriteLine(); Console.WriteLine(ex); if (Environment.UserInteractive) { Thread.Sleep(3000); } return(1); } }
public void Constructor1SetsTimeout() { var timeout = TimeSpan.FromMilliseconds(1234); var consoleLogProvider = new ConsoleLogProvider(timeout: timeout); consoleLogProvider.Timeout.Should().Be(timeout); }
public void Constructor2SetsFormatter() { var logFormatter = new Mock <ILogFormatter>().Object; var consoleLogProvider = new ConsoleLogProvider(logFormatter); consoleLogProvider.Formatter.Should().BeSameAs(logFormatter); }
public void Constructor1SetsFormatterToTemplateLogFormatter() { var consoleLogProvider = new ConsoleLogProvider("foo"); consoleLogProvider.Formatter.Should().BeOfType <TemplateLogFormatter>(); var formatter = (TemplateLogFormatter)consoleLogProvider.Formatter; formatter.Template.Should().Be("foo"); }
public static Logger CreateLogger(string type) { switch (type.ToLower()) { case "stdout": case "console": var p = new ConsoleLogProvider(); var logger = new Logger(p); return(logger); default: throw new ArgumentException("无法识别的logger类型。", nameof(type)); } }
public async Task WriteLineAsyncFormatsTheLogEntryAndWritesItToConsole(ConsoleLogProvider.Output output) { var sb = new StringBuilder(); using (var writer = new StringWriter(sb)) { Action revert; if (output == ConsoleLogProvider.Output.StdOut) { var original = Console.Out; Console.SetOut(writer); revert = () => Console.SetOut(original); } else { var original = Console.Error; Console.SetError(writer); revert = () => Console.SetError(original); } try { var consoleLogProvider = new ConsoleLogProvider("{level}:{message}", output: output); var logEntry = new LogEntry("Hello, world!", LogLevel.Info); await consoleLogProvider.WriteAsync(logEntry); } finally { revert(); } } sb.ToString().Should().Be($"Info:Hello, world!{Environment.NewLine}"); }
public static Logger CreateLogger(string type) { Logger logger; switch (type.ToLower()) { case "stdout": case "debug": case "console": var cp = new ConsoleLogProvider(); logger = new Logger(cp); break; case "file": var fp = new FileLogProvider(); logger = new Logger(fp); break; default: throw new ArgumentException("无法识别的logger类型。", type); } return(logger); }
private static ILogWriter GetWarn(ConsoleLogProvider log) { return new ConsoleLogWriter(() => log.IsEnabled(LogLevel.Warn), ConsoleColor.Yellow); }
private static ILogWriter GetInfo(ConsoleLogProvider log) { return new ConsoleLogWriter(() => log.IsEnabled(LogLevel.Info), ConsoleColor.White); }
private static ILogWriter GetFatal(ConsoleLogProvider log) { return new ConsoleLogWriter(() => log.IsEnabled(LogLevel.Fatal), ConsoleColor.Red); }
private static ILogWriter GetDebug(ConsoleLogProvider log) { return new ConsoleLogWriter(() => log.IsEnabled(LogLevel.Debug), ConsoleColor.Cyan); }
public ConsoleLogger(string name, ConsoleLogProvider provider) : base(name, GetDebug(provider), GetInfo(provider), GetWarn(provider), GetError(provider), GetFatal(provider)) { }
public void InitializeConsoleAndProvider() { console = new StringWriter(); Console.SetOut(console); provider = new ConsoleLogProvider(); }
public void Constructor1SetsLevel() { var consoleLogProvider = new ConsoleLogProvider(level: LogLevel.Warn); consoleLogProvider.Level.Should().Be(LogLevel.Warn); }