Exemplo n.º 1
0
        static void Main(string[] args)
        {
            //Initialize the metrics manager. This method should be called only once!
            MetricsManager.Initialize("SampleApp", "Development", "localhost");

            //Imitate long-running taks and get the timings
            //should be resolved in ~500ms
            using (var timer = MetricsManager.GetRootMetricsLogger().StartTimer("Timer"))
            {
                Task.Delay(500).Wait();
            }

            //service also allows you to extend the logging experience by grouping metrics
            //together via dimensions. The line below creates a new logger with additional
            //property `api`.
            var logger = MetricsManager.GetMetricsLogger("api=Counters");
            //and then extends an existing logger by adding more specifi property
            var extendedLogger = logger.ExtendDimensions("subApi=Recorders");

            //Imitate concurrent environment, create counter and record metrics and update them
            Parallel.For(0, 1000, (i) => {
                logger.IncrementCounter("MyCounter", 1);
                extendedLogger.Record("MyRecorder", 1.0M, Unit.Second);
            });

            //If the 'IsManualFlush' config key is set to false, then the next line is redundant
            //as metrics manager will automatically flush things
            // MetricsManager.FlushAll();

            Console.ReadKey();
        }
Exemplo n.º 2
0
 public void GetRootMetricsLogger()
 {
     Assert.Null(Record.Exception(() =>
     {
         MetricsManager.GetRootMetricsLogger().IncrementCounter("NumOfExceptions", 1);
         MetricsManager.GetRootMetricsLogger().Flush();
         MetricsManager.FlushAll();
     }));
 }