当前位置: 首页>>代码示例>>C#>>正文


C# TelemetryClient.Flush方法代码示例

本文整理汇总了C#中Microsoft.ApplicationInsights.TelemetryClient.Flush方法的典型用法代码示例。如果您正苦于以下问题:C# TelemetryClient.Flush方法的具体用法?C# TelemetryClient.Flush怎么用?C# TelemetryClient.Flush使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Microsoft.ApplicationInsights.TelemetryClient的用法示例。


在下文中一共展示了TelemetryClient.Flush方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Main

        public static void Main(string[] args)
        {
            var config = new Configuration();
            var telemetry = new TelemetryClient();
            telemetry.InstrumentationKey = config.InstrumentationKey;
            telemetry.Context.Device.Id = Environment.MachineName;
            telemetry.Context.Session.Id = Guid.NewGuid().ToString();
            telemetry.Context.Location.Ip = Dns.GetHostEntryAsync(Dns.GetHostName())
                                                .Result
                                                .AddressList
                                                .FirstOrDefault(addr => addr.AddressFamily == AddressFamily.InterNetwork)
                                                .ToString();

            using (var amz = new AmazonSynchronizer(config, telemetry))
            {
                amz.WithInterval(TimeSpan.FromSeconds(1))
                    .StopWhen((obj) => false)
                    .Start(CancellationToken.None)
                    .Wait();
            }

            if (telemetry != null)
                telemetry.Flush();

            Console.WriteLine("Sync Server Stopped.Press any key to exit ...");
            Console.ReadKey();
        }
开发者ID:Zoltu,项目名称:bags-amazon-synchronizer,代码行数:27,代码来源:Program.cs

示例2: Initialize

    /// <summary>
    /// Initializes the telemetry client.
    /// </summary>
    public static void Initialize(IServiceProvider serviceProvider, string version, string telemetryKey)
    {
        if (_telemetry != null)
            throw new NotSupportedException("The telemetry client is already initialized");

        var dte = (DTE2)serviceProvider.GetService(typeof(DTE));

        _telemetry = new TelemetryClient();
        _telemetry.Context.Session.Id = Guid.NewGuid().ToString();
        _telemetry.Context.Device.Model = dte.Edition;
        _telemetry.InstrumentationKey = telemetryKey;
        _telemetry.Context.Component.Version = version;

        byte[] enc = Encoding.UTF8.GetBytes(Environment.UserName + Environment.MachineName);
        using (var crypto = new MD5CryptoServiceProvider())
        {
            byte[] hash = crypto.ComputeHash(enc);
            _telemetry.Context.User.Id = Convert.ToBase64String(hash);
        }

        _events = dte.Events.DTEEvents;
        _events.OnBeginShutdown += delegate { _telemetry.Flush(); };

        Enabled = true;
    }
开发者ID:modulexcite,项目名称:MicrosoftBandTools,代码行数:28,代码来源:Telemetry.cs

示例3: Application_Start

        protected void Application_Start()
        { 
            // Read instrumentation key from azure web app settings
            string ikeyValue = Environment.GetEnvironmentVariable("APPINSIGHTS_INSTRUMENTATIONKEY");

            if (!string.IsNullOrEmpty(ikeyValue))
            {
                TelemetryConfiguration.Active.InstrumentationKey = ikeyValue;
            }

            try
            {

                AreaRegistration.RegisterAllAreas();

                GlobalConfiguration.Configure(WebApiConfig.Register);
                FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
                RouteConfig.RegisterRoutes(RouteTable.Routes);
                BundleConfig.RegisterBundles(BundleTable.Bundles);
                BindingConfig.RegisterGlobalBindings(ModelBinders.Binders, GlobalConfiguration.Configuration);
                FormatterConfig.RegisterFormatters(GlobalConfiguration.Configuration);

                ReleaseSettings.Settings.Options.PackageListingPath = Server.MapPath("~/Content/packages.json");
                ReleaseSettings.Settings.Initialize();

                PackageSettings.Settings.NugetListingPath = Server.MapPath("~/Content/nuget.json");
                PackageSettings.Settings.Initialize();

                TwitterSettings.Settings.Initialize();

                BuildSettings.Settings.Initialize();

                BlogSettings.Settings.Initialize();

                ContributorSettings.Settings.Options.ContributorListingPath = Server.MapPath("~/Content/committers.json");
                ContributorSettings.Settings.Initialize();
            }
            catch (Exception ex)
            {
                TelemetryClient client = new TelemetryClient();
                ExceptionTelemetry excTelemetry = new ExceptionTelemetry(ex);
                excTelemetry.HandledAt = ExceptionHandledAt.Unhandled;
                client.TrackException(excTelemetry);

                // this exception will terminate the process. Let's wait till telemetry will be delivered
                client.Flush();
                Thread.Sleep(1000);

                throw;
            }
        }
开发者ID:trucnguyendev,项目名称:Glimpse.Site,代码行数:51,代码来源:Global.asax.cs

示例4: CurrentDomain_UnhandledException

        private void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e)
        {
            if (ChatterBox.Client.Common.Settings.SignalingSettings.AppInsightsEnabled)
            {
                ExceptionTelemetry excTelemetry = new ExceptionTelemetry((Exception)e.Exception);
                excTelemetry.SeverityLevel = SeverityLevel.Critical;
                excTelemetry.HandledAt = ExceptionHandledAt.Unhandled;
                excTelemetry.Timestamp = System.DateTimeOffset.UtcNow;
                var telemetry = new TelemetryClient();
                telemetry.TrackException(excTelemetry);

                telemetry.Flush();
            }
        }
开发者ID:hungdluit,项目名称:ChatterBox,代码行数:14,代码来源:App.xaml.cs

示例5: Start

        public static void Start()
        {
            if (CoreApp.DoNotTrack())
              {
            return;
              }

              Log.Debug("Insights - starting");

              try
              {
            var configuration = TelemetryConfiguration.Active;
            Assert.IsNotNull(configuration, "configuration");

            configuration.TelemetryChannel = new PersistenceChannel("Sitecore Instance Manager");
            configuration.InstrumentationKey = "1447f72f-2d39-401b-91ac-4d5c502e3359";

            var client = new TelemetryClient(configuration)
            {
              InstrumentationKey = "1447f72f-2d39-401b-91ac-4d5c502e3359"
            };

            Analytics.telemetryClient = client;
            try
            {
              // ReSharper disable PossibleNullReferenceException
              client.Context.Component.Version = string.IsNullOrEmpty(ApplicationManager.AppVersion) ? "0.0.0.0" : ApplicationManager.AppVersion;
              client.Context.Session.Id = Guid.NewGuid().ToString();
              client.Context.User.Id = Environment.MachineName + "\\" + Environment.UserName;
              client.Context.User.AccountId = CoreApp.GetCookie();
              client.Context.Device.OperatingSystem = Environment.OSVersion.ToString();
              // ReSharper restore PossibleNullReferenceException
              client.TrackEvent("Start");
              client.Flush();
            }
            catch (Exception ex)
            {
              client.TrackException(ex);
              Log.Error(ex, "Error in app insights");
            }
              }
              catch (Exception ex)
              {
            Log.Error(ex, "Error in app insights");
              }

              Log.Debug("Insights - started");
        }
开发者ID:Sitecore,项目名称:Sitecore-Instance-Manager,代码行数:48,代码来源:Analytics.cs

示例6: TrackPackageNotFound

        public static void TrackPackageNotFound(string id, string version, string logFileName)
        {
            if (!_initialized)
            {
                return;
            }

            var telemetryClient = new TelemetryClient();
            var telemetry = new EventTelemetry("PackageNotFound");
            telemetry.Properties.Add("PackageId", id);
            telemetry.Properties.Add("PackageVersion", version);
            telemetry.Properties.Add("LogFile", logFileName);

            telemetryClient.TrackEvent(telemetry);
            telemetryClient.Flush();
        }
开发者ID:girish,项目名称:NuGet.Jobs,代码行数:16,代码来源:ApplicationInsights.cs

示例7: GenerateUnobservedException

        private static void GenerateUnobservedException(TelemetryClient client)
        {
            Task.Factory.StartNew(() => { throw new Exception(); });

            HardWork(TimeSpan.FromSeconds(5));

            // This forces exception to become unobserved
            GC.Collect(2, GCCollectionMode.Forced);
            GC.WaitForPendingFinalizers();

            HardWork(TimeSpan.FromSeconds(5));

            client.Flush();

            HardWork(TimeSpan.FromSeconds(5));
        }
开发者ID:gregjhogan,项目名称:ApplicationInsights-server-dotnet,代码行数:16,代码来源:Program.cs

示例8: Initialize

        /// <summary>
        /// Initializes the telemetry client.
        /// </summary>
        public static void Initialize(DTE2 dte, string version, string telemetryKey)
        {
            if (_telemetry != null)
                throw new NotSupportedException("The telemetry client is already initialized");

            _telemetry = new TelemetryClient();
            _telemetry.Context.Session.Id = Guid.NewGuid().ToString();
            _telemetry.Context.User.Id = (Environment.UserName + Environment.MachineName).GetHashCode().ToString();
            _telemetry.Context.Device.Model = dte.Edition;
            _telemetry.InstrumentationKey = telemetryKey;
            _telemetry.Context.Component.Version = version;

            _events = dte.Events.DTEEvents;
            _events.OnBeginShutdown += delegate { _telemetry.Flush(); };

            Enabled = true;
        }
开发者ID:yannduran,项目名称:OpenCommandLine,代码行数:20,代码来源:Telemetry.cs

示例9: TrackMetric

        public static void TrackMetric(string metricName, double value, string logFileName)
        {
            if (!_initialized)
            {
                return;
            }

            var telemetryClient = new TelemetryClient();
            var telemetry = new MetricTelemetry(metricName, value);

            if (!string.IsNullOrWhiteSpace(logFileName))
            {
                telemetry.Properties.Add("LogFile", logFileName);
            }

            telemetryClient.TrackMetric(telemetry);
            telemetryClient.Flush();
        }
开发者ID:girish,项目名称:NuGet.Jobs,代码行数:18,代码来源:ApplicationInsights.cs

示例10: TrackException

        public static void TrackException(Exception exception, string logFileName = null)
        {
            if (!_initialized)
            {
                return;
            }

            var telemetryClient = new TelemetryClient();
            var telemetry = new ExceptionTelemetry(exception);

            if (!string.IsNullOrWhiteSpace(logFileName))
            {
                telemetry.Properties.Add("LogFile", logFileName);
            }

            telemetryClient.TrackException(telemetry);
            telemetryClient.Flush();
        }
开发者ID:girish,项目名称:NuGet.Jobs,代码行数:18,代码来源:ApplicationInsights.cs

示例11: Start

    public static void Start()
    {
      if (string.IsNullOrEmpty(ApplicationManager.AppVersion) || EnvironmentHelper.DoNotTrack())
      {
        return;
      }

      Log.Debug("Insights - starting");

      try
      {
        var tc = new TelemetryClient(new TelemetryConfiguration
        {
          InstrumentationKey = "1447f72f-2d39-401b-91ac-4d5c502e3359",
          TelemetryChannel = new PersistenceChannel()
        });

        client = tc;
        try
        {
          tc.Context.Session.Id = Guid.NewGuid().ToString();
          tc.Context.User.Id = Environment.MachineName + "\\" + Environment.UserName;
          tc.Context.User.AccountId = EnvironmentHelper.GetCookie();
          tc.Context.Device.OperatingSystem = Environment.OSVersion.ToString();
          tc.TrackEvent("Start");
          tc.Flush();
        }
        catch (Exception ex)
        {
          tc.TrackException(ex);
          Log.Error(ex, "Error in app insights");
        }
      }
      catch (Exception ex)
      {
        Log.Error(ex, "Error in app insights");
      }

      Log.Debug("Insights - started");
    }
开发者ID:lennartfranke,项目名称:Sitecore-Instance-Manager,代码行数:40,代码来源:Analytics.cs

示例12: Main

        /// <summary>
        /// This is the entry point of the service host process.
        /// </summary>
        private static void Main()
        {
            try
            {
                TelemetryClient = new TelemetryClient();
            }
            catch (Exception)
            {
                // ignored
            }
            try
            {
                // Create default garbage collection settings for all the actor types
                var actorGarbageCollectionSettings = new ActorGarbageCollectionSettings(300, 60);

                // This line registers your actor class with the Fabric Runtime.
                // The contents of your ServiceManifest.xml and ApplicationManifest.xml files
                // are automatically populated when you build this project.
                // For more information, see http://aka.ms/servicefabricactorsplatform

                ActorRuntime.RegisterActorAsync<DeviceActor>(
                   (context, actorType) => new DeviceActorService(context, actorType, () => new DeviceActor(), null, new ActorServiceSettings
                   {
                       ActorGarbageCollectionSettings = actorGarbageCollectionSettings
                   })).GetAwaiter().GetResult();

                Thread.Sleep(Timeout.Infinite);
            }
            catch (Exception e)
            {
                TelemetryClient.TrackException(e);
                ActorEventSource.Current.ActorHostInitializationFailed(e);
                throw;
            }
            finally
            {
                TelemetryClient.Flush();
            }
        }
开发者ID:paolosalvatori,项目名称:servicefabriceventhubdemo,代码行数:42,代码来源:Program.cs

示例13: Main

    static void Main()
    {
      Console.WriteLine("Hello, this is a trace");

      try
      {
        var eventHubString =
          ConfigurationManager.ConnectionStrings["EventHubConnection"];

        var eventHubName =
          ConfigurationManager.ConnectionStrings["EventHubName"];

        var appInsightsKey =
          ConfigurationManager.ConnectionStrings["AppInsightsKey"];

        var nsm = NamespaceManager.CreateFromConnectionString(eventHubString.ConnectionString);

        var hub = nsm.GetEventHub(eventHubName.ConnectionString);

        TelemetryClient appInsights = new TelemetryClient();
        appInsights.InstrumentationKey = appInsightsKey.ConnectionString;
        var telemetryData = new EventTelemetry()
        {
          Name = "Event Hub Heartbeat",
        };
        telemetryData.Properties.Add("Status", hub.Status.ToString());
        appInsights.TrackEvent(telemetryData);
        appInsights.Flush();

        Console.Write($"Service status is at {hub.Status}");
      }
      catch
      {
        Console.WriteLine("Catch handler");
      }

      Console.WriteLine("We're done");
    }
开发者ID:amykatenicho,项目名称:ms-band-azure,代码行数:38,代码来源:Program.cs

示例14: TrackTelemetryOnIndexReopened

        private static void TrackTelemetryOnIndexReopened(object sender, SegmentInfoEventArgs e)
        {
            var telemetryClient = new TelemetryClient();

            // track the index reopened event
            var eventTelemetry = new EventTelemetry("Index Reopened");
            eventTelemetry.Metrics.Add("Segment Count", e.Segments.Count());
            eventTelemetry.Metrics.Add("Segment Size (Sum)", e.Segments.Sum(s => s.NumDocs));

            telemetryClient.TrackEvent(eventTelemetry);


            foreach (var segment in e.Segments)
            {
                var metricTelemetry = new MetricTelemetry("Segment Size", segment.NumDocs);
                metricTelemetry.Properties.Add("Segment Name", segment.Name);

                telemetryClient.TrackMetric(metricTelemetry);
            }

            telemetryClient.Flush();
        }
开发者ID:darrelmiller,项目名称:NuGet.Services.Search,代码行数:22,代码来源:Startup.cs

示例15: TrackReportProcessed

        public static void TrackReportProcessed(string reportName, string packageId = null)
        {
            if (!_initialized)
            {
                return;
            }

            var telemetryClient = new TelemetryClient();
            var telemetry = new MetricTelemetry(reportName, 1);

            if (!string.IsNullOrWhiteSpace(packageId))
            {
                telemetry.Properties.Add("Package Id", packageId);
            }

            telemetryClient.TrackMetric(telemetry);
            telemetryClient.Flush();
        }
开发者ID:girish,项目名称:NuGet.Jobs,代码行数:18,代码来源:ApplicationInsights.cs


注:本文中的Microsoft.ApplicationInsights.TelemetryClient.Flush方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。