Пример #1
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IHostingEnvironment env,
                              ILoggerFactory loggerFactory,
                              IServiceProvider serviceProvider)
        {
            var logging = new FilterLoggerSettings();

            logging.Add("Microsoft.AspNetCore.Hosting.Internal.WebHost", LogLevel.Error);
            logging.Add("Microsoft.AspNetCore.Mvc", LogLevel.Error);
            logging.Add("Microsoft.AspNetCore.Server.Kestrel", LogLevel.Error);
            loggerFactory
            .WithFilter(logging)
            .AddConsole();

            app.UseMvc();


            var builder = serviceProvider.GetService <ConfigurationBuilder>() ?? new ConfigurationBuilder();

            Configuration = builder.Build();

            var config  = serviceProvider.GetService <TumblerRuntime>();
            var options = GetMVCOptions(serviceProvider);

            Serializer.RegisterFrontConverters(options.SerializerSettings, config.Network);
        }
Пример #2
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IHostingEnvironment env,
                              ILoggerFactory loggerFactory,
                              IServiceProvider serviceProvider)
        {
            app.Use(req =>
            {
                return(async(ctx) =>
                {
                    try
                    {
                        await req(ctx);
                    }
                    catch (Exception ex)
                    {
                        Logs.Tumbler.LogCritical(new EventId(), ex, "Unhandled exception thrown by the Tumbler Service");
                        var webEx = ex as WebException;
                        if (webEx != null)
                        {
                            try
                            {
                                var httpResp = ((HttpWebResponse)webEx.Response);
                                var reader = new StreamReader(httpResp.GetResponseStream(), Encoding.UTF8);
                                Logs.Tumbler.LogCritical($"Web Exception {(int)httpResp.StatusCode} {reader.ReadToEnd()}");
                            }
                            catch { }
                        }
                        throw;
                    }
                });
            });
            var logging = new FilterLoggerSettings();

            logging.Add("Microsoft.AspNetCore.Hosting.Internal.WebHost", LogLevel.Error);
            logging.Add("Microsoft.AspNetCore.Mvc", LogLevel.Error);
            logging.Add("Microsoft.AspNetCore.Server.Kestrel", LogLevel.Error);
            logging.Add("TCPServer", LogLevel.Error);
            loggerFactory
            .WithFilter(logging)
            .AddConsole();

            app.UseMvc();


            var builder = serviceProvider.GetService <ConfigurationBuilder>() ?? new ConfigurationBuilder();

            Configuration = builder.Build();

            var config  = serviceProvider.GetService <TumblerRuntime>();
            var options = GetMVCOptions(serviceProvider);

            Serializer.RegisterFrontConverters(options.SerializerSettings, config.Network);
        }
Пример #3
0
        public static void AttachSerilog(this ILoggerFactory lf, Serilog.ILogger logger,
                                         IReadOnlyDictionary <string, LogLevel> filters = null)
        {
            lf.AddSerilog(logger);

            var flSettings = new FilterLoggerSettings();

            foreach (var f in filters)
            {
                flSettings.Add(f.Key, f.Value);
            }
            lf.WithFilter(flSettings);
        }
Пример #4
0
        public static void Main(string[] args)
        {
            var settings = new FilterLoggerSettings();

            settings.Add("Microsoft", LogLevel.Warning);

            ILoggerFactory factory = new LoggerFactory()
                                     .WithFilter(new FilterLoggerSettings
            {
                { "Microsoft", LogLevel.Warning },
                { "LoggingSample.Program", LogLevel.Information }
            });

            factory.AddConsole();
            factory.AddDebug();
            _logger = factory.CreateLogger <Program>();

            _logger.LogInformation(1, "started at '{StartTime:T}'", DateTimeOffset.Now);
            _logger.ProgramStarting(DateTimeOffset.Now);
        }
Пример #5
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IHostingEnvironment env,
                              ILoggerFactory loggerFactory,
                              IServiceProvider serviceProvider)
        {
            var logging = new FilterLoggerSettings();

            //Disable aspnet core logs
            logging.Add("Microsoft.AspNetCore", LogLevel.Error);

            loggerFactory
            .WithFilter(logging)
            .AddConsole();

            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }

            var fullNode = serviceProvider.GetService <FullNode>();

            RPCAuthorization authorizedAccess = new RPCAuthorization();
            var cookieStr = "__cookie__:" + new uint256(RandomUtils.GetBytes(32));

            File.WriteAllText(fullNode.DataFolder.RPCCookieFile, cookieStr);
            authorizedAccess.Authorized.Add(cookieStr);
            if (fullNode.Settings.RPC.RpcPassword != null)
            {
                authorizedAccess.Authorized.Add(fullNode.Settings.RPC.RpcUser + ":" + fullNode.Settings.RPC.RpcPassword);
            }
            authorizedAccess.AllowIp.AddRange(fullNode.Settings.RPC.AllowIp);


            var options = GetMVCOptions(serviceProvider);

            Serializer.RegisterFrontConverters(options.SerializerSettings, fullNode.Network);
            app.UseMiddleware(typeof(RPCMiddleware), authorizedAccess);
            app.UseRPC();
        }
Пример #6
0
        public static ILoggerFactory GetLoggerFactory(string[] args)
        {
            // TODO: preload enough args for -conf= or -datadir= to get debug args from there
            // TODO: currently only takes -debug arg
            var debugArgs = args.GetValueOf("-debug");

            var keyToCategory = new Dictionary <string, string>(StringComparer.OrdinalIgnoreCase)
            {
                //{ "addrman", "" },
                //{ "alert", "" },
                { "bench", "Stratis.Bitcoin.FullNode.ConsensusStats" },
                //{ "coindb", "" },
                { "db", "Stratis.Bitcoin.BlockStore" },
                //{ "lock", "" },
                //{ "rand", "" },
                { "rpc", "Stratis.Bitcoin.RPC" },
                //{ "selectcoins", "" },
                { "mempool", "Stratis.Bitcoin.MemoryPool" },
                //{ "mempoolrej", "" },
                { "net", "Stratis.Bitcoin.Connection" },
                //{ "proxy", "" },
                //{ "prune", "" },
                //{ "http", "" },
                //{ "libevent", "" },
                //{ "tor", "" },
                //{ "zmq", "" },
                //{ "qt", "" },

                // Short Names
                { "estimatefee", "Stratis.Bitcoin.Fee" },
                { "configuration", "Stratis.Bitcoin.Configuration" },
                { "fullnode", "Stratis.Bitcoin.FullNode" },
                { "consensus", "Stratis.Bitcoin.FullNode" },
                { "mining", "Stratis.Bitcoin.FullNode" },
                { "wallet", "Stratis.Bitcoin.Wallet" },
            };

            // get the minimum log level. The default is Information.
            LogLevel minLogLevel = LogLevel.Information;
            var      logLevelArg = args.GetValueOf("-loglevel");

            if (!string.IsNullOrEmpty(logLevelArg))
            {
                var result = Enum.TryParse(logLevelArg, true, out minLogLevel);
                if (!result)
                {
                    minLogLevel = LogLevel.Information;
                }
            }

            var filterSettings = new FilterLoggerSettings();

            // Default level is Information
            filterSettings.Add("Default", minLogLevel);
            // TODO: Probably should have a way to configure these as well
            filterSettings.Add("System", LogLevel.Warning);
            filterSettings.Add("Microsoft", LogLevel.Warning);
            // Disable aspnet core logs (retained from ASP.NET config)
            filterSettings.Add("Microsoft.AspNetCore", LogLevel.Error);

            if (!string.IsNullOrWhiteSpace(debugArgs))
            {
                if (debugArgs.Trim() == "1")
                {
                    // Increase all logging to Trace
                    filterSettings.Add("Stratis.Bitcoin", LogLevel.Trace);
                }
                else
                {
                    // Increase selected categories to Trace
                    var categoryKeys = debugArgs.Split(',');
                    foreach (var key in categoryKeys)
                    {
                        string category;
                        if (keyToCategory.TryGetValue(key.Trim(), out category))
                        {
                            filterSettings.Add(category, LogLevel.Trace);
                        }
                        else
                        {
                            // Can directly specify something like -debug=Stratis.Bitcoin.Miner
                            filterSettings.Add(key, LogLevel.Trace);
                        }
                    }
                }
            }

            // TODO: Additional args
            //var logipsArgs = args.GetValueOf("-logips");
            //var printtoconsoleArgs = args.GetValueOf("-printtoconsole");

            ILoggerFactory loggerFactory = new LoggerFactory()
                                           .WithFilter(filterSettings);

            loggerFactory.AddDebug(LogLevel.Trace);
            loggerFactory.AddConsole(LogLevel.Trace);
            loggerFactory.AddFile("Logs/node-{Date}.json", isJson: true, minimumLevel: LogLevel.Trace, fileSizeLimitBytes: 5000000);
            return(loggerFactory);
        }
Пример #7
0
        public static ILoggerFactory GetLoggerFactory(string[] args)
        {
            // TODO: preload enough args for -conf= or -datadir= to get debug args from there
            // TODO: currently only takes -debug arg
            var debugArgs = args.Where(a => a.StartsWith("-debug=")).Select(a => a.Substring("-debug=".Length).Replace("\"", "")).FirstOrDefault();

            var keyToCategory = new Dictionary <string, string>(StringComparer.OrdinalIgnoreCase)
            {
                //{ "addrman", "" },
                //{ "alert", "" },
                { "bench", "Stratis.Bitcoin.FullNode.ConsensusStats" },
                //{ "coindb", "" },
                { "db", "Stratis.Bitcoin.BlockStore" },
                //{ "lock", "" },
                //{ "rand", "" },
                { "rpc", "Stratis.Bitcoin.RPC" },
                //{ "selectcoins", "" },
                { "mempool", "Stratis.Bitcoin.MemoryPool" },
                //{ "mempoolrej", "" },
                { "net", "Stratis.Bitcoin.Connection" },
                //{ "proxy", "" },
                //{ "prune", "" },
                //{ "http", "" },
                //{ "libevent", "" },
                //{ "tor", "" },
                //{ "zmq", "" },
                //{ "qt", "" },

                // Short Names
                { "estimatefee", "Stratis.Bitcoin.Fee" },
                { "configuration", "Stratis.Bitcoin.Configuration" },
                { "fullnode", "Stratis.Bitcoin.FullNode" },
                { "consensus", "Stratis.Bitcoin.FullNode" },
                { "mining", "Stratis.Bitcoin.FullNode" },
            };
            var filterSettings = new FilterLoggerSettings();

            // Default level is Information
            filterSettings.Add("Default", LogLevel.Information);
            // TODO: Probably should have a way to configure these as well
            filterSettings.Add("System", LogLevel.Warning);
            filterSettings.Add("Microsoft", LogLevel.Warning);
            // Disable aspnet core logs (retained from ASP.NET config)
            filterSettings.Add("Microsoft.AspNetCore", LogLevel.Error);

            if (!string.IsNullOrWhiteSpace(debugArgs))
            {
                if (debugArgs.Trim() == "1")
                {
                    // Increase all logging to Trace
                    filterSettings.Add("Stratis.Bitcoin", LogLevel.Trace);
                }
                else
                {
                    // Increase selected categories to Trace
                    var categoryKeys = debugArgs.Split(',');
                    foreach (var key in categoryKeys)
                    {
                        string category;
                        if (keyToCategory.TryGetValue(key.Trim(), out category))
                        {
                            filterSettings.Add(category, LogLevel.Trace);
                        }
                        else
                        {
                            // Can directly specify something like -debug=Stratis.Bitcoin.Miner
                            filterSettings.Add(key, LogLevel.Trace);
                        }
                    }
                }
            }

            // TODO: Additional args
            //var logipsArgs = args.Where(a => a.StartsWith("-logips=")).Select(a => a.Substring("-logips=".Length).Replace("\"", "")).FirstOrDefault();
            //var printtoconsoleArgs = args.Where(a => a.StartsWith("-printtoconsole=")).Select(a => a.Substring("-printtoconsole=".Length).Replace("\"", "")).FirstOrDefault();

            ILoggerFactory loggerFactory = new LoggerFactory()
                                           .WithFilter(filterSettings);

            loggerFactory.AddDebug(LogLevel.Trace);
            loggerFactory.AddConsole(LogLevel.Trace);

            // TODO: To add file logging, need to get -datadir / -config from args

            return(loggerFactory);
        }
        public static void AddFilters(this ILoggerFactory loggerFactory, LogSettings settings)
        {
            // TODO: preload enough args for -conf= or -datadir= to get debug args from there
            // TODO: currently only takes -debug arg

            var keyToCategory = new Dictionary <string, string>(StringComparer.OrdinalIgnoreCase)
            {
                //{ "addrman", "" },
                //{ "alert", "" },
                { "bench", "Stratis.Bitcoin.FullNode.ConsensusStats" },
                //{ "coindb", "" },
                { "db", "Stratis.Bitcoin.BlockStore" },
                //{ "lock", "" },
                //{ "rand", "" },
                { "rpc", "Stratis.Bitcoin.RPC" },
                //{ "selectcoins", "" },
                { "mempool", "Stratis.Bitcoin.MemoryPool" },
                //{ "mempoolrej", "" },
                { "net", "Stratis.Bitcoin.Connection" },
                //{ "proxy", "" },
                //{ "prune", "" },
                //{ "http", "" },
                //{ "libevent", "" },
                //{ "tor", "" },
                //{ "zmq", "" },
                //{ "qt", "" },

                // Short Names
                { "estimatefee", "Stratis.Bitcoin.Fee" },
                { "configuration", "Stratis.Bitcoin.Configuration" },
                { "fullnode", "Stratis.Bitcoin.FullNode" },
                { "consensus", "Stratis.Bitcoin.FullNode" },
                { "mining", "Stratis.Bitcoin.FullNode" },
                { "wallet", "Stratis.Bitcoin.Wallet" },
            };


            var filterSettings = new FilterLoggerSettings();

            // Default level is Information
            filterSettings.Add("Default", settings.LogLevel);
            // TODO: Probably should have a way to configure these as well
            filterSettings.Add("System", LogLevel.Warning);
            filterSettings.Add("Microsoft", LogLevel.Warning);
            // Disable aspnet core logs (retained from ASP.NET config)
            filterSettings.Add("Microsoft.AspNetCore", LogLevel.Error);

            if (settings.DebugArgs.Any())
            {
                if (settings.DebugArgs[0] == "1")
                {
                    // Increase all logging to Trace
                    filterSettings.Add("Stratis.Bitcoin", LogLevel.Trace);
                }
                else
                {
                    // Increase selected categories to Trace
                    foreach (var key in settings.DebugArgs)
                    {
                        string category;
                        if (keyToCategory.TryGetValue(key.Trim(), out category))
                        {
                            filterSettings.Add(category, LogLevel.Trace);
                        }
                        else
                        {
                            // Can directly specify something like -debug=Stratis.Bitcoin.Miner
                            filterSettings.Add(key, LogLevel.Trace);
                        }
                    }
                }
            }

            // TODO: Additional args
            //var logipsArgs = args.GetValueOf("-logips");
            //var printtoconsoleArgs = args.GetValueOf("-printtoconsole");

            loggerFactory.WithFilter(filterSettings);
        }