Exemple #1
0
        public void Constructor1SetsTimeoutToDefaultTimeoutWhenParameterIsNull()
        {
            var timeout            = TimeSpan.FromMilliseconds(1234);
            var consoleLogProvider = new ConsoleLogProvider(timeout: null);

            consoleLogProvider.Timeout.Should().Be(ConsoleLogProvider.DefaultTimeout);
        }
Exemple #2
0
        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);
            }
        }
Exemple #3
0
        public void Constructor1SetsTimeout()
        {
            var timeout            = TimeSpan.FromMilliseconds(1234);
            var consoleLogProvider = new ConsoleLogProvider(timeout: timeout);

            consoleLogProvider.Timeout.Should().Be(timeout);
        }
Exemple #4
0
        public void Constructor2SetsFormatter()
        {
            var logFormatter = new Mock <ILogFormatter>().Object;

            var consoleLogProvider = new ConsoleLogProvider(logFormatter);

            consoleLogProvider.Formatter.Should().BeSameAs(logFormatter);
        }
Exemple #5
0
        public void Constructor1SetsFormatterToTemplateLogFormatter()
        {
            var consoleLogProvider = new ConsoleLogProvider("foo");

            consoleLogProvider.Formatter.Should().BeOfType <TemplateLogFormatter>();
            var formatter = (TemplateLogFormatter)consoleLogProvider.Formatter;

            formatter.Template.Should().Be("foo");
        }
Exemple #6
0
        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}");
        }
Exemple #8
0
        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);
        }
Exemple #9
0
 private static ILogWriter GetWarn(ConsoleLogProvider log)
 {
     return new ConsoleLogWriter(() => log.IsEnabled(LogLevel.Warn), ConsoleColor.Yellow);
 }
Exemple #10
0
 private static ILogWriter GetInfo(ConsoleLogProvider log)
 {
     return new ConsoleLogWriter(() => log.IsEnabled(LogLevel.Info), ConsoleColor.White);
 }
Exemple #11
0
 private static ILogWriter GetFatal(ConsoleLogProvider log)
 {
     return new ConsoleLogWriter(() => log.IsEnabled(LogLevel.Fatal), ConsoleColor.Red);
 }
Exemple #12
0
 private static ILogWriter GetDebug(ConsoleLogProvider log)
 {
     return new ConsoleLogWriter(() => log.IsEnabled(LogLevel.Debug), ConsoleColor.Cyan);
 }
Exemple #13
0
 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();
 }
Exemple #15
0
        public void Constructor1SetsLevel()
        {
            var consoleLogProvider = new ConsoleLogProvider(level: LogLevel.Warn);

            consoleLogProvider.Level.Should().Be(LogLevel.Warn);
        }