Ejemplo n.º 1
0
        private void Setup(IEncompassConfig config)
        {
            _prefix = config.GetValue(GRAPHITE_ROOT_NAMESPACE, "");

            if (config.GetValue(GRAPHITE_TRACK_HOSTMACHINE, true))
            {
                _prefix = $"{_prefix}.{Environment.MachineName}";
            }

            var host = config.GetValue(GRAPHITE_HOST);

            if (string.IsNullOrEmpty(host))
            {
                throw new InvalidOperationException($"{GRAPHITE_HOST} is a required configuration");
            }

            var port = config.GetValue(GRAPHITE_PORT, -1);

            if (port < 0)
            {
                throw new InvalidOperationException($"{GRAPHITE_PORT} is a required configuration");
            }

            _client = new TcpClient(host, port);
        }
        public static void Setup(IEncompassConfig config)
        {
            var elasticSearchEnabled = config.GetValue(ElasticsearchLogAppender.ELASTICSEARCH_ENABLED, false);

            if (elasticSearchEnabled)
            {
                AddAppender(new ElasticsearchLogAppender(config));
            }

            var fileEnabled = config.GetValue(FileLogAppender.FILE_ENABLED, false);

            if (fileEnabled)
            {
                AddAppender(new FileLogAppender(config));
            }
            var consoleEnabled = config.GetValue(ConsoleLogAppender.CONSOLE_ENABLED, false);

            if (consoleEnabled)
            {
                AddAppender(new ConsoleLogAppender(config));
            }

            var logglyEnabled = config.GetValue(LogglyLogAppender.LOGGLY_ENABLED, false);

            if (logglyEnabled)
            {
                AddAppender(new LogglyLogAppender(config));
            }
        }
 public FileLogAppender(IEncompassConfig config)
     : base(config.GetValue(FILE_QUEUE_SIZE, 1000),
            config.GetValue(FILE_RETRY_LIMIT, 3))
 {
     _tags = new HashSet <string>();
     Setup(config);
 }
Ejemplo n.º 4
0
 public ElasticsearchLogAppender(IEncompassConfig config)
     : base(config.GetValue(ELASTICSEARCH_QUEUE_SIZE, 1000),
            config.GetValue(ELASTICSEARCH_RETRY_LIMIT, 3))
 {
     _tags = new HashSet <string>();
     Setup(config);
 }
Ejemplo n.º 5
0
 internal static LogglyConfiguration GetLogglyConfig(IEncompassConfig config) =>
 new LogglyConfiguration
 {
     CustomerToken    = config.GetValue(Logger.LOGGLY_APIKEY),
     EndpointHostName = config.GetValue(Logger.LOGGLY_URL, "logs-01.loggly.com").Replace("https://", string.Empty).Replace("http://", string.Empty),
     EndpointPort     = 443,
     ThrowExceptions  = true,
     ApplicationName  = config.GetValue(Logger.LOGGLY_APPLICATION_NAME, "Unnamed Sextant App"),
     Tags             = new List <string>(config.GetValue(Logger.LOGGLY_TAGS, "").Split(new[] { '|', ',' }, StringSplitOptions.RemoveEmptyEntries))
 };
        protected void Setup(IEncompassConfig config)
        {
            var allEnabled   = config.GetValue(LOGGLY_ALL, false);
            var errorEnabled = config.GetValue(LOGGLY_ERROR, false);
            var warnEnabled  = config.GetValue(LOGGLY_WARN, false);
            var infoEnabled  = config.GetValue(LOGGLY_INFO, false);
            var debugEnabled = config.GetValue(LOGGLY_DEBUG, false);
            var fatalEnabled = config.GetValue(LOGGLY_FATAL, false);

            AllEnabled   = allEnabled;
            ErrorEnabled = allEnabled || errorEnabled;
            WarnEnabled  = allEnabled || warnEnabled;
            InfoEnabled  = allEnabled || infoEnabled;
            DebugEnabled = allEnabled || debugEnabled;
            FatalEnabled = allEnabled || fatalEnabled;

            if (_tags == null)
            {
                _tags = new HashSet <string>();
            }

            var configTags = config.GetValue(LOGGLY_TAGS, string.Empty);

            if (!string.IsNullOrEmpty(configTags))
            {
                foreach (var tag in configTags.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries))
                {
                    AddTag(tag);
                }
            }

            var url = CreateUrl(config.GetValue(LOGGLY_URL), config.GetValue(LOGGLY_APIKEY));

            CreateClient(url);
        }
Ejemplo n.º 7
0
        internal static ElasticsearchSinkOptions GetElasticOptions(IEncompassConfig config)
        {
            var elasticOptions = new ElasticsearchSinkOptions(new Uri(config.GetValue(Logger.ELASTICSEARCH_URL, "NOT PROVIDED")));
            var indexFormat    = config.GetValue(Logger.ELASTICSEARCH_INDEX_NAME, "sextant-serilog-");

            if (!indexFormat.Contains("{"))
            {
                indexFormat += "{0:yyyy.MM.dd}";
            }

            elasticOptions.IndexFormat          = indexFormat;
            elasticOptions.MinimumLogEventLevel = GetMinLevel(config, "ELASTICSEARCH");
            elasticOptions.EmitEventFailure     = EmitEventFailureHandling.ThrowException;
            return(elasticOptions);
        }
Ejemplo n.º 8
0
 private static LogEventLevel SetLogglyEventLevelFromConfig(IEncompassConfig config)
 {
     if (Convert.ToBoolean(config.GetValue(Logging.Logger.LOGGLY_ALL)))
     {
         return(LogEventLevel.Verbose);
     }
     else if (Convert.ToBoolean(config.GetValue(Logging.Logger.LOGGLY_DEBUG)))
     {
         return(LogEventLevel.Debug);
     }
     else if (Convert.ToBoolean(config.GetValue(Logging.Logger.LOGGLY_VERBOSE)))
     {
         return(LogEventLevel.Verbose);
     }
     else if (Convert.ToBoolean(config.GetValue(Logging.Logger.LOGGLY_INFO)))
     {
         return(LogEventLevel.Information);
     }
     else if (Convert.ToBoolean(config.GetValue(Logging.Logger.LOGGLY_WARN)))
     {
         return(LogEventLevel.Warning);
     }
     else if (Convert.ToBoolean(config.GetValue(Logging.Logger.LOGGLY_ERROR)))
     {
         return(LogEventLevel.Error);
     }
     else if (Convert.ToBoolean(config.GetValue(Logging.Logger.LOGGLY_FATAL)))
     {
         return(LogEventLevel.Fatal);
     }
     else
     {
         return(LogEventLevel.Warning);
     }
 }
        public DatadogReporter(IEncompassConfig config)
            : base(CreateUrl(config.GetValueFunction(DATADOG_URL), config.GetValueFunction(DATADOG_APIKEY)),
                   config.GetValue(DATADOG_QUEUE_SIZE, 1000),
                   config.GetValue(DATADOG_RETRY_LIMIT, 3))
        {
            Setup(config.GetValue(DATADOG_TRACK_HOSTMACHINE, true));
            var tags = config.GetValue(DATADOG_TAGS, "");

            if (!string.IsNullOrEmpty(tags))
            {
                var trimmedTags = tags.Split(',')
                                  .Select(s => s.Trim())
                                  .Where(s => !string.IsNullOrEmpty(s))
                                  .ToList();

                trimmedTags.ForEach(t => jsonTags.Add(t));
            }
        }
Ejemplo n.º 10
0
        public static void Setup(IEncompassConfig config)
        {
            var metricConfig = Metric.Config;

            var statsdTags = config.GetValue(STATSD_METRICS_TAGS, "");
            var globalTags = TrimTags(statsdTags);

            var datadogEnabled = config.GetValue(DatadogReporter.DATADOG_ENABLED, false);

            if (datadogEnabled)
            {
                var datadogTags = TrimTags(config.GetValue(DatadogReporter.DATADOG_TAGS));

                if (datadogTags.Any())
                {
                    globalTags.AddRange(datadogTags);
                }

                metricConfig.WithReporting(
                    report =>
                    report.WithDatadog(config.GetValue(DatadogReporter.DATADOG_APIKEY),
                                       Environment.MachineName,
                                       config.GetValue(DatadogReporter.DATADOG_ROOTNAMESPACE),
                                       TimeSpan.FromSeconds(1)));
            }

            var graphiteEnabled = config.GetValue(GraphiteReporter.GRAPHITE_ENABLED, false);

            if (graphiteEnabled)
            {
                var grapiteTags = TrimTags(config.GetValue(GraphiteReporter.GRAPHITE_TAGS));

                if (grapiteTags.Any())
                {
                    globalTags.AddRange(grapiteTags);
                }

                var gs = new TcpGraphiteSender(config.GetValue(GraphiteReporter.GRAPHITE_HOST), config.GetValue(GraphiteReporter.GRAPHITE_PORT, 0));
                var gr = new StatsDGraphiteReport(gs, config.GetValue(GraphiteReporter.GRAPHITE_ROOT_NAMESPACE, string.Empty));

                metricConfig.WithReporting(report => report.WithReport(gr, TimeSpan.FromSeconds(1)));
            }

            if (globalTags.Any())
            {
                _globalTags = new MetricTags(globalTags);
            }
        }
Ejemplo n.º 11
0
 protected void Setup(IEncompassConfig config)
 {
     AllEnabled   = config.GetValue(CONSOLE_ALL, true);
     ErrorEnabled = config.GetValue(CONSOLE_ERROR, true);
     WarnEnabled  = config.GetValue(CONSOLE_WARN, true);
     InfoEnabled  = config.GetValue(CONSOLE_INFO, true);
     DebugEnabled = config.GetValue(CONSOLE_DEBUG, true);
     FatalEnabled = config.GetValue(CONSOLE_FATAL, true);
     _tags        = new HashSet <string>();
 }
 public LogglyLogAppender(IEncompassConfig config)
     : base(CreateUrl(config.GetValue(LOGGLY_URL), config.GetValue(LOGGLY_APIKEY)),
            config.GetValue(LOGGLY_QUEUE_SIZE, 1000),
            config.GetValue(LOGGLY_RETRY_LIMIT, 3))
 {
     _url    = config.GetValue(LOGGLY_URL);
     _apiKey = config.GetValue(LOGGLY_APIKEY);
     _tags   = new HashSet <string>();
     Setup(config);
 }
        public void Setup(IEncompassConfig config)
        {
            var allEnabled   = config.GetValue(FILE_ALL, true);
            var errorEnabled = config.GetValue(FILE_ERROR, true);
            var warnEnabled  = config.GetValue(FILE_WARN, true);
            var infoEnabled  = config.GetValue(FILE_INFO, true);
            var debugEnabled = config.GetValue(FILE_DEBUG, true);
            var fatalEnabled = config.GetValue(FILE_FATAL, true);

            LogFolder    = config.GetValue(LOG_FOLDER, System.IO.Path.GetTempPath());
            LogName      = config.GetValue(LOG_NAME, "Sextant_log");
            AllEnabled   = allEnabled;
            ErrorEnabled = allEnabled || errorEnabled;
            WarnEnabled  = allEnabled || warnEnabled;
            InfoEnabled  = allEnabled || infoEnabled;
            DebugEnabled = allEnabled || debugEnabled;
            FatalEnabled = allEnabled || fatalEnabled;
        }
        private void Setup(IEncompassConfig config, string clientId, string context)
        {
            var tags = new Dictionary <string, string>();

            tags.Add("assembly", GetAssemblyNameSafely());
            tags.Add("version", GetVersionSafely());
            tags.Add("environment", config.GetValue("Encompass.Environment"));

            if (!string.IsNullOrEmpty(context))
            {
                tags.Add("context", context);
            }
            if (!string.IsNullOrEmpty(clientId))
            {
                tags.Add("clientid", clientId);
            }

            Setup(config, tags);
        }
        /// <summary>
        /// Initializes the loggly logger
        /// </summary>
        /// <param name="session">Current encompass session, used to load the config file</param>
        /// <param name="config">Config file to load.  Will re-initialize when this is used.</param>
        /// <param name="tags">Collection of loggly tags.  If null, we will load the Loggly.Tags element from the config.</param>
        public static void Init(Session session, IEncompassConfig config, ICollection<string> tags = null)
        {
            config.Init(session);
            if (tags != null)
            {
                foreach (string tag in tags)
                {
                    AddTag(tag);
                }
            }
            
           foreach (var tag in config.GetValue(LOGGLY_TAGS, string.Empty).Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries))
            { 
                    AddTag(tag);
            }

            string configLogglyUrl = config.GetValue(LOGGLY_URL);

            if (configLogglyUrl != null)
            {
                SetPostUrl(configLogglyUrl);
            }
            bool allEnabled = config.GetValue(LOGGLY_ALL, false);
            bool errorEnabled = config.GetValue(LOGGLY_ERROR, false);
            bool warnEnabled = config.GetValue(LOGGLY_WARN, false);
            bool infoEnabled = config.GetValue(LOGGLY_INFO, false);
            bool debugEnabled = config.GetValue(LOGGLY_DEBUG, false);
            bool fatalEnabled = config.GetValue(LOGGLY_FATAL, false);

            Instance.ErrorEnabled = allEnabled || errorEnabled;
            Instance.WarnEnabled = allEnabled || warnEnabled;
            Instance.InfoEnabled = allEnabled || infoEnabled;
            Instance.DebugEnabled = allEnabled || debugEnabled;
            Instance.FatalEnabled = allEnabled || fatalEnabled;
        }
Ejemplo n.º 16
0
        public static Serilog.ILogger Setup(IEncompassConfig config)
        {
            lock (syncRoot)
            {
                if (configured)
                {
                    throw new Exception("Already Setup for this AppDomain.");
                }

                try
                {
                    var baseLogger = new LoggerConfiguration()
                                     .WriteTo.Logger(aa => aa.MinimumLevel.Verbose())
                                     .Enrich.FromLogContext()
                                     .Enrich.WithExceptionDetails()
                                     .Enrich.WithMachineName()
                                     .Enrich.WithProcessId()
                                     .Enrich.WithEnvironmentUserName()
                                     .Enrich.WithProcessName()
                                     .Enrich.WithAssemblyName()
                                     .Enrich.WithAssemblyVersion();

                    baseLogger.WriteTo.Logger(aa => aa.Destructure.ToMaximumDepth(20));

                    if (config.GetValue(Logging.Logger.ELASTICSEARCH_ENABLED, false))
                    {
                        baseLogger.WriteTo.Elasticsearch(SerilogHelpers.GetElasticOptions(config));
                    }

                    if (config.GetValue(Logging.Logger.FILE_ENABLED, false))
                    {
                        baseLogger.WriteTo.RollingFile(pathFormat: config.GetValue(
                                                           Logging.Logger.FILE_FOLDER, config.GetValue(Logging.Logger.FILE_NAME)),
                                                       formatter: new JsonFormatter(renderMessage: false),
                                                       fileSizeLimitBytes: config.GetValue(Logging.Logger.FILE_MAX_FILE_BYTES, 10000),
                                                       retainedFileCountLimit: config.GetValue(Logging.Logger.FILE_MAX_FILES, 10));
                    }

                    if (config.GetValue(Logging.Logger.LOGGLY_ENABLED, false))
                    {
                        LogEventLevel eventLevel = SetLogglyEventLevelFromConfig(config);
                        baseLogger.WriteTo.Loggly(logglyConfig: SerilogHelpers.GetLogglyConfig(config), formatProvider: CultureInfo.CurrentCulture,
                                                  restrictedToMinimumLevel: eventLevel);
                    }

                    if (config.GetValue(Logging.Logger.CONSOLE_ENABLED, false))
                    {
                        baseLogger.WriteTo.Console(new JsonFormatter(null, false, null));
                    }

                    Log.Logger = baseLogger.CreateLogger();

                    configured = true;
                }
                catch (Exception ex)
                {
                    Console.WriteLine($"ERROR CONFIGURING LOGGING: {ex}");
                }
            }

            return(Serilog.Log.Logger);
        }
Ejemplo n.º 17
0
        internal static LogEventLevel GetMinLevel(IEncompassConfig config, string prefix)
        {
            string all_key;
            string debug_key;
            string info_key;
            string warn_key;
            string error_key;
            string fatal_key;

            switch (prefix)
            {
            case "FILE":
                all_key   = Logger.FILE_ALL;
                debug_key = Logger.FILE_DEBUG;
                info_key  = Logger.FILE_INFO;
                warn_key  = Logger.FILE_WARN;
                error_key = Logger.FILE_ERROR;
                fatal_key = Logger.FILE_FATAL;
                break;

            case "ELASTICSEARCH":
                all_key   = Logger.ELASTICSEARCH_ALL;
                debug_key = Logger.ELASTICSEARCH_DEBUG;
                info_key  = Logger.ELASTICSEARCH_INFO;
                warn_key  = Logger.ELASTICSEARCH_WARN;
                error_key = Logger.ELASTICSEARCH_ERROR;
                fatal_key = Logger.ELASTICSEARCH_FATAL;
                break;

            case "CONSOLE":
                all_key   = Logger.CONSOLE_ALL;
                debug_key = Logger.CONSOLE_DEBUG;
                info_key  = Logger.CONSOLE_INFO;
                warn_key  = Logger.CONSOLE_WARN;
                error_key = Logger.CONSOLE_ERROR;
                fatal_key = Logger.CONSOLE_FATAL;
                break;

            default:
                all_key   = Logger.LOGGLY_ALL;
                debug_key = Logger.LOGGLY_DEBUG;
                info_key  = Logger.LOGGLY_INFO;
                warn_key  = Logger.LOGGLY_WARN;
                error_key = Logger.LOGGLY_ERROR;
                fatal_key = Logger.CONSOLE_FATAL;
                break;
            }

            if (config.GetValue(all_key, false))
            {
                return(LogEventLevel.Verbose);
            }
            if (config.GetValue(debug_key, false))
            {
                return(LogEventLevel.Debug);
            }
            if (config.GetValue(info_key, false))
            {
                return(LogEventLevel.Information);
            }
            if (config.GetValue(warn_key, false))
            {
                return(LogEventLevel.Warning);
            }
            if (config.GetValue(error_key, false))
            {
                return(LogEventLevel.Error);
            }
            if (config.GetValue(fatal_key, false))
            {
                return(LogEventLevel.Fatal);
            }
            return(LogEventLevel.Error);
        }
Ejemplo n.º 18
0
        protected void Setup(IEncompassConfig config)
        {
            var url = config.GetValue(ELASTICSEARCH_URL);

            _node      = new Uri(url);
            _settings  = new ConnectionSettings(_node);
            _client    = new ElasticClient(_settings);
            _indexName = config.GetValue(ELASTICSEARCH_INDEX_NAME, "SextantLogger").ToLower();
            var allEnabled   = config.GetValue(ELASTICSEARCH_ALL, true);
            var errorEnabled = config.GetValue(ELASTICSEARCH_ERROR, true);
            var warnEnabled  = config.GetValue(ELASTICSEARCH_WARN, true);
            var infoEnabled  = config.GetValue(ELASTICSEARCH_INFO, true);
            var debugEnabled = config.GetValue(ELASTICSEARCH_DEBUG, true);
            var fatalEnabled = config.GetValue(ELASTICSEARCH_FATAL, true);

            LogRecurisively = config.GetValue(ELASTICSEARCH_LOG_RECURSIVELY, true);
            _environment    = config.GetValue(ELASTICSEARCH_ENVIRONMENT, String.Empty);
            _appName        = config.GetValue(ELASTICSEARCH_APPNAME, String.Empty);

            //e.g. if we fail writing a log to Elasticsearch, log the error to Elasticsearch.
            AllEnabled   = allEnabled;
            ErrorEnabled = allEnabled || errorEnabled;
            WarnEnabled  = allEnabled || warnEnabled;
            InfoEnabled  = allEnabled || infoEnabled;
            DebugEnabled = allEnabled || debugEnabled;
            FatalEnabled = allEnabled || fatalEnabled;

            if (_tags == null)
            {
                _tags = new HashSet <string>();
            }

            var configTags = config.GetValue(ELASTICSEARCH_TAGS, string.Empty);

            if (!string.IsNullOrEmpty(configTags))
            {
                foreach (var tag in configTags.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries))
                {
                    AddTag(tag);
                }
            }
        }
Ejemplo n.º 19
0
        public static void Setup(IEncompassConfig config, Dictionary <string, string> additionalTags = null)
        {
            LoggerConfiguration baseLogger = null;

            lock (syncRoot)
            {
                try
                {
                    //Serilog has a clever "enricher" approach, but it is created at setup time and wouldn't be easily compatible with how we add tags to logs now.  We could make this a future enhancement.  For now, just add these to each log event when we log.
                    _additionalTags = new ConcurrentDictionary <string, string>();
                    if (!ReferenceEquals(additionalTags, null))
                    {
                        foreach (var kv in additionalTags)
                        {
                            _additionalTags.TryAdd(kv.Key, kv.Value);
                        }
                    }

                    baseLogger = new LoggerConfiguration()
                                 .WriteTo.Logger(aa => aa.MinimumLevel.Verbose())
                                 .Enrich.FromLogContext()
                                 .Enrich.WithExceptionDetails()
                                 .Enrich.WithMachineName()
                                 .Enrich.WithProcessId()
                                 .Enrich.WithEnvironmentUserName()
                                 .Enrich.WithProcessName();

                    baseLogger.WriteTo.Logger(aa => aa.Destructure.ToMaximumDepth(20));

                    if (config.GetValue(Logger.ELASTICSEARCH_ENABLED, false))
                    {
                        baseLogger.WriteTo.Elasticsearch(SerilogHelpers.GetElasticOptions(config));
                    }

                    if (config.GetValue(Logger.FILE_ENABLED, false))
                    {
                        baseLogger.WriteTo.RollingFile(pathFormat: config.GetValue(
                                                           Logger.FILE_FOLDER, config.GetValue(Logger.FILE_NAME)),
                                                       formatter: new JsonFormatter(null, false, null),
                                                       fileSizeLimitBytes: config.GetValue(Logger.FILE_MAX_FILE_BYTES, 10000),
                                                       retainedFileCountLimit: config.GetValue(Logger.FILE_MAX_FILES, 10));
                    }

                    if (config.GetValue(Logger.LOGGLY_ENABLED, false))
                    {
                        Serilog.Events.LogEventLevel eventLevel;
                        eventLevel = SetLogglyEventLevelFromConfig(config);
                        baseLogger.WriteTo.Loggly(logglyConfig: SerilogHelpers.GetLogglyConfig(config), formatProvider: CultureInfo.CurrentCulture,
                                                  restrictedToMinimumLevel: eventLevel);
                    }

                    if (config.GetValue(Logger.CONSOLE_ENABLED, false))
                    {
                        baseLogger.WriteTo.Console(new JsonFormatter(null, false, null));
                    }

                    Serilog.Log.Logger = baseLogger.CreateLogger();

                    configured = true;
                }
                catch (Exception ex)
                {
                    System.Console.WriteLine($"ERROR CONFIGURING LOGGING: {ex}");
                }
            }
        }
Ejemplo n.º 20
0
 public GraphiteReporter(IEncompassConfig config)
     : base(config.GetValue(GRAPHITE_QUEUE_SIZE, 1000),
            config.GetValue(GRAPHITE_RETRY_LIMIT, 3))
 {
     Setup(config);
 }