Example #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);
        }
        /// <summary>
        /// Registers a wrapper logger which provides a common way to filter log messages across all registered
        ///  <see cref="ILoggerProvider"/>s.
        /// </summary>
        /// <param name="loggerFactory">The logger factory.</param>
        /// <param name="settings">The filter settings which get applied to all registered logger providers.</param>
        /// <returns>
        /// A wrapped <see cref="ILoggerFactory"/> which provides common filtering across all registered
        ///  logger providers.
        /// </returns>
        public static ILoggerFactory WithFilter(this ILoggerFactory loggerFactory, Action <FilterLoggerSettings> settingsConfig)
        {
            var settings = new FilterLoggerSettings();

            settingsConfig?.Invoke(settings);
            return(new FilterLoggerFactory(loggerFactory, settings));
        }
        public static void ConfigureLogger(ILoggerFactory loggerFactory)
        {
            var filterLoggerSettings = new FilterLoggerSettings
            {
                { "Microsoft", LogLevel.Error },
                { "System", LogLevel.Error },
            };

            loggerFactory = loggerFactory.WithFilter(filterLoggerSettings);
            loggerFactory.AddFile(_filePath);
        }
        public ESLoggerProvider(IServiceProvider serviceProvider)
        {
            _httpContextAccessor = serviceProvider.GetService <IHttpContextAccessor>();

            _esClient = serviceProvider.GetService <ESClientProvider>();
            _esClient.EnsureIndexWithMapping <LogEntry>();

            _filter = new FilterLoggerSettings
            {
                { "*", _esClient.LogLevel }
            };
        }
Example #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)
        {
            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);
        }
Example #6
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);
        }
Example #7
0
        public ESLoggerProvider(IServiceProvider serviceProvider, string indexName = null, FilterLoggerSettings filter = null)
        {
            _httpContextAccessor = serviceProvider.GetService <IHttpContextAccessor>();
            _indexName           = indexName;

            _esClient = serviceProvider.GetService <ESClientProvider>();
            _esClient.EnsureIndexWithMapping <LogEntry>(indexName);

            _filter = filter ?? new FilterLoggerSettings
            {
                { "*", LogLevel.Warning }
            };
        }
        public ElmahIoLoggerProvider(string apiKey, Guid logId, ElmahIoProviderOptions options = null)
        {
#if NETSTANDARD1_1
            _filter = new FilterLoggerSettings
            {
                { "*", LogLevel.Warning }
            };
#endif
            _apiKey         = apiKey;
            _logId          = logId;
            _options        = options ?? new ElmahIoProviderOptions();
            _options.ApiKey = apiKey;
            _options.LogId  = logId;
        }
        public ElmahIoLoggerProvider(string apiKey, Guid logId, FilterLoggerSettings filter = null, ElmahIoProviderOptions options = null)
        {
            _apiKey = apiKey;
            _logId  = logId;

            if (filter == null)
            {
                filter = new FilterLoggerSettings
                {
                    { "*", LogLevel.Warning }
                };
            }
            _filter = filter;

            _options = options ?? new ElmahIoProviderOptions();
        }
Example #10
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)
        {
            var filterLoggerSettings = new FilterLoggerSettings
            {
                { "Microsoft", LogLevel.Error },
                { "System", LogLevel.Error },
            };

            loggerFactory = loggerFactory.WithFilter(filterLoggerSettings);
            loggerFactory.AddFile(Configuration["Logging:LogFile"]);

            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }
            else
            {
                app.UseHsts();
                app.UseCustomExceptionHandling();
            }

            app.UseAuthentication();

            app.UseHttpsRedirection();
            app.UseStaticFiles();
            app.UseSpaStaticFiles();

            app.UseMvc(routes =>
            {
                routes.MapRoute(
                    name: "default",
                    template: "{controller}/{action=Index}/{id?}");
            });

            app.UseSpa(spa =>
            {
                spa.Options.SourcePath = "ClientApp";

                if (env.IsDevelopment())
                {
                    spa.UseReactDevelopmentServer(npmScript: "start");
                }
            });
        }
Example #11
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);
        }
Example #12
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();
        }
Example #13
0
 public static ILoggerFactory AddElmahIo(this ILoggerFactory factory, string apiKey, Guid logId, FilterLoggerSettings filter, ElmahIoProviderOptions options)
 {
     factory.AddProvider(new ElmahIoLoggerProvider(apiKey, logId, filter, options));
     return(factory);
 }
Example #14
0
 public static ILoggerFactory AddESLogger(this ILoggerFactory factory, IServiceProvider serviceProvider, string indexName = null, FilterLoggerSettings filter = null)
 {
     factory.AddProvider(new ESLoggerProvider(serviceProvider, indexName, filter));
     return(factory);
 }
        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);
        }
        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);
        }
Example #17
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);
        }