Exemple #1
0
        public Reporter()
        {
            IMetricsReporterBuilder builder = new MetricsReporterBuilder(
                _activationFactory,
                _simpleConfig,
                TelemetryTagContext.Default);

            Metric = builder.Build();

            var activation = _activationFactory.Create();

            //var configuration = new ConfigurationBuilder()
            //                     .AddJsonFile("TelemetryConfig.json")
            //                     .Build();

            var logConfig = new LoggerConfiguration();

            logConfig = logConfig//.ReadFrom.AppSettings()
                        .MinimumLevel.Verbose()
                        .MinimumLevel.Override("WebToInfluxTake2.Controllers.DataController", LogEventLevel.Warning)
                        .WriteTo.File("log.debug.txt", restrictedToMinimumLevel: LogEventLevel.Debug, outputTemplate: FORMAT)
                        .WriteTo.File("log.error.txt", restrictedToMinimumLevel: LogEventLevel.Error, outputTemplate: FORMAT)
                        .WriteTo.File("log.warn.txt", restrictedToMinimumLevel: LogEventLevel.Warning, outputTemplate: FORMAT)
                        .WriteTo.Logger(l => l
                                        .Filter.ByIncludingOnly(Matching.FromSource("WebToInfluxTake2.Controllers.DataController"))
                                        .WriteTo.File("log.data.txt", outputTemplate: FORMAT))
            ;
            //.WriteTo.WithActivation(
            //    activation, "seq",
            //    s => s.Seq("http://localhost:5341",restrictedToMinimumLevel: Serilog.Events.LogEventLevel.Debug));

            LogFactory  = new LogFactory(logConfig, activation);
            PushContext = _telemetryPushContext;
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="MetricsReporterBuilder"/> class.
        /// </summary>
        /// <param name="activationFactory">The activation factory.</param>
        /// <param name="simpleConfig">The simple configuration.</param>
        /// <param name="tagContext">The tag context.</param>
        public MetricsReporterBuilder(
            ITelemetryActivationFactory activationFactory,
            ISimpleConfig simpleConfig,
            ITelemetryTagContext tagContext)
        {
            // TODO: move it into Influx provider (InfluxMetricFactory)
            string url     = simpleConfig["influx-url"];
            string db      = simpleConfig["influx-database"];
            string version = simpleConfig["influx-report-version"];

            _activation          = activationFactory.Create();
            _influxConfiguration = new CollectorConfiguration()
                                   .Tag.With("version", version)
                                   .Tag.With("host", Environment.MachineName)
                                   .Tag.With("user", Environment.UserName)
                                   .Batch.AtInterval(TimeSpan.FromSeconds(5))
                                   .WriteTo.InfluxDB(url, database: db);
            _tagContext = tagContext;
        }