Ejemplo n.º 1
0
        public static void Main()
        {
            Log.Logger = new LoggerConfiguration()
                         .Enrich.With <FlowContextEnricher>()
                         //.WriteTo.Console(outputTemplate: "{Timestamp:HH:mm:ss.fff} {Level} {Message:l} {Exception}{NewLine}{Properties}{NewLine}")
                         .WriteTo.VostokLog(new ConsoleLog())
                         .CreateLogger();

            var log = new SerilogLog(Log.Logger)
                      .ForContext(typeof(EntryPoint));

            while (true)
            {
                using (Context.Properties.Use("TraceId", Guid.NewGuid()))
                {
                    log.Info("Hello {Username}!", "Mike");
                }

                log.Info("Hello Bob!");

                Thread.Sleep(10000);
            }
        }
Ejemplo n.º 2
0
        public static void Main(string[] args)
        {
            var container = new Container(new ContainerConfiguration(AssembliesLoader.Load()));
            var settings  = ApplicationSettings.LoadDefault("godLikeTools.csf");

            container.Configurator.ForAbstraction <IApplicationSettings>().UseInstances(settings);
            container.ConfigureRepositories();

            var logger = new SerilogLog(SerilogConfigurator.ConfigureLogger(settings.GetString("LogDirectory")).WithConsole().CreateLogger());

            container.Configurator.ForAbstraction <ILog>().UseInstances(logger);

            var commandLine = new CommandLine(args);
            var command     = commandLine.GetCommandLineSetting("-mode");

            var processorTypes = Assembly.GetExecutingAssembly()
                                 .GetTypes()
                                 .Where(x => typeof(ICommandProcessor).IsAssignableFrom(x))
                                 .ToArray();

            var processorsGroup = processorTypes.GroupBy(x => x.Name).FirstOrDefault(group => group.Count() > 1);

            if (processorsGroup != null)
            {
                throw new Exception("Some processors have same command descriptions: " + processorsGroup.First().Name);
            }

            var processorType = processorTypes.SingleOrDefault(x => x.Name == command);

            if (processorType == null)
            {
                throw new BadCommandLineException("The list of available commands: " +
                                                  string.Join(", ", processorTypes.Select(p => p.Name)));
            }

            var processor = (ICommandProcessor)container.Get(processorType);

            processor.Run(commandLine);
            container.Dispose();
            logger.Info($"GodLikeTool Processor in mode '{command}' completed");
        }