コード例 #1
0
        static void Main(string[] args)
        {
            // Cmdr: A CommandLine Arguments Parser
            Cmdr.NewWorker(RootCmd.New(
                               new AppInfo {
                AppName = "mdx-tool",
            }, (root) =>
            {
                root.AddCommand(new Command
                {
                    Short    = "lkp", Long = "lookup", Description = "dictionary lookup tool",
                    TailArgs = "<Mdx Files (*.mdx;*.mdd)> <word-pattern>",
                    Action   = (lookupAction)
                });

                root.AddCommand(new Command
                {
                    Short       = "ls", Long = "list",
                    Description = "list a dictionary entries and dump for debugging",
                    TailArgs    = "<Mdx Files (*.mdx;*.mdd)>",
                    Action      = (listAction)
                });

                root.AddCommand(new Command {
                    Short = "t", Long = "tags", Description = "tags operations"
                }
                                .AddCommand(new TagsAddCmd())
                                .AddCommand(new TagsRemoveCmd())
                                // .AddCommand(new TagsAddCmd { }) // dup-test
                                .AddCommand(new TagsListCmd())
                                .AddCommand(new TagsModifyCmd())
                                );
            }),            // <- RootCmd
                           // Options ->
                           (w) =>
            {
                w.SetLogger(SerilogBuilder.Build((logger) =>
                {
                    logger.EnableCmdrLogInfo  = false;
                    logger.EnableCmdrLogTrace = false;
                }));

                // w.EnableDuplicatedCharThrows = true;
            })
            .Run(args);

            // HzNS.MdxLib.Core.Open("*.mdx,mdd,sdx,wav,png,...") => mdxfile
            // mdxfile.Preload()
            // mdxfile.GetEntry("beta") => entryInfo.{item,index}
            // mdxfile.Find("a")           // "a", "a*b", "*b"
            // mdxfile.Close()
            // mdxfile.Find()
            // mdxfile.Find()
            // mdxfile.Find()

            // Log.CloseAndFlush();
            // Console.ReadKey();
        }
コード例 #2
0
        /// <inheritdoc />
        public void Register([NotNull] IServiceConventionContext context)
        {
            if (context == null)
            {
                throw new ArgumentNullException(nameof(context));
            }

            context.Services.AddSingleton <ILoggerFactory>(
                _ =>
            {
                if (_options.WriteToProviders)
                {
                    var providerCollection = _.GetRequiredService <LoggerProviderCollection>();
                    var factory            = new SerilogLoggerFactory(_.GetRequiredService <global::Serilog.ILogger>(), true, providerCollection);

                    foreach (var provider in _.GetServices <ILoggerProvider>())
                    {
                        factory.AddProvider(provider);
                    }

                    return(factory);
                }

                return(new SerilogLoggerFactory(_.GetRequiredService <global::Serilog.ILogger>(), true));
            }
                );
            context.Services.AddHostedService <SerilogFinalizerHostedService>();

            var loggerConfiguration = context.GetOrAdd(() => new LoggerConfiguration());

            if (_options.WriteToProviders)
            {
                var loggerProviderCollection = context.GetOrAdd(() => new LoggerProviderCollection());
                context.Services.AddSingleton(loggerProviderCollection);
                loggerConfiguration.WriteTo.Providers(loggerProviderCollection);
            }

            var serilogBuilder = new SerilogBuilder(
                _scanner,
                context.AssemblyProvider,
                context.AssemblyCandidateFinder,
                context.Environment,
                context.Configuration,
                loggerConfiguration,
                _diagnosticSource,
                context.Properties
                );

            var logger = serilogBuilder.Build();

            if (!_options.PreserveStaticLogger)
            {
                Log.Logger = logger;
            }

            context.Services.AddSingleton(logger);
        }
コード例 #3
0
ファイル: Program.cs プロジェクト: hedzr/Cmdr.Core
        static void Main(string[] args)
        {
            var log = Log.Logger;

            log.Information("YES IT IS");

            // throw new Exception("sys");

            // Cmdr: A CommandLine Arguments Parser
            Cmdr.NewWorker(RootCommand.New(new AppInfo {
                AppName = "commander"
            }, (root) =>
            {
                root.AddCommand(new Command {
                    Short = "t", Long = "tags", Description = "tags operations"
                }
                                .AddCommand(new TagsAddCmd())
                                .AddCommand(new TagsRemoveCmd())
                                // .AddCommand(new TagsAddCmd { }) // dup-test
                                .AddCommand(new TagsListCmd())
                                .AddCommand(new TagsModifyCmd())
                                );
            }),         // <- RootCmd
                        // Options ->
                           (w) =>
            {
                //
                // w.UseSerilog((configuration) => configuration.WriteTo.Console().CreateLogger())
                //
                w.SetLogger(SerilogBuilder.Build((logger) =>
                {
                    logger.EnableCmdrLogInfo  = false;
                    logger.EnableCmdrLogTrace = false;
                }));

                // w.EnableDuplicatedCharThrows = true;
            })
            .Run(args);

            // HzNS.MdxLib.Core.Open("*.mdx,mdd,sdx,wav,png,...") => mdxfile
            // mdxfile.Preload()
            // mdxfile.GetEntry("beta") => entryInfo.{item,index}
            // mdxfile.Find("a")           // "a", "a*b", "*b"
            // mdxfile.Close()
            // mdxfile.Find()
            // mdxfile.Find()
            // mdxfile.Find()

            // Log.CloseAndFlush();
            // Console.ReadKey();
        }
コード例 #4
0
        public static IWebHostBuilder UseSerilog(this IWebHostBuilder hostBuilder,
                                                 Action <WebHostBuilderContext, ILoggingBuilder, LoggerConfiguration> configureLogging = default)
        {
            hostBuilder.ConfigureLogging((hostingContext, loggingBuilder) =>
            {
                var serilogBuilder = new SerilogBuilder(hostingContext.Configuration)
                                     .WithEnvironment(hostingContext.HostingEnvironment.EnvironmentName)
                                     .WithConfig(configuration =>
                {
                    configureLogging?.Invoke(hostingContext, loggingBuilder, configuration);
                    return(configuration);
                });

                Log.Logger = serilogBuilder.Build();
                GlobalLog.SetSerilog(Log.Logger);

                loggingBuilder.Services.AddSingleton(Log.Logger);
            });

            return(hostBuilder);
        }
コード例 #5
0
ファイル: Program.cs プロジェクト: Pastafarian/DevBlog
        public static int Main(string[] args)
        {
            var(appSettings, loggerSettings) = ConfigurationHelper.GetSettings();

            Log.Logger = SerilogBuilder.Build <Program>(appSettings, loggerSettings);

            try
            {
                Log.Information("Starting web host");
                CreateHostBuilder(args).Build().Run();
                return(0);
            }
            catch (Exception ex)
            {
                Log.Information("Exception Here");
                Log.Fatal(ex, "Host terminated unexpectedly");
                return(1);
            }
            finally
            {
                Log.CloseAndFlush();
            }
        }