當前位置: 首頁>>代碼示例>>C#>>正文


C# DataContracts.EventTelemetry類代碼示例

本文整理匯總了C#中Microsoft.ApplicationInsights.DataContracts.EventTelemetry的典型用法代碼示例。如果您正苦於以下問題:C# EventTelemetry類的具體用法?C# EventTelemetry怎麽用?C# EventTelemetry使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


EventTelemetry類屬於Microsoft.ApplicationInsights.DataContracts命名空間,在下文中一共展示了EventTelemetry類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: Dispose

        private bool disposedValue = false; // To detect redundant calls

        /// <summary>
        /// Releases unmanaged and - optionally - managed resources.
        /// </summary>
        /// <param name="disposing"><c>true</c> to release both managed and unmanaged resources; <c>false</c> to release only unmanaged resources.</param>
        protected virtual void Dispose(bool disposing)
        {
            if (!disposedValue)
            {
                if (disposing)
                {
                    var eventTelemetry = new EventTelemetry(_eventName)
                    {
                        Timestamp = _startTime,
                    };

                    this.Properties.ToList().ForEach(p => eventTelemetry.Properties.Add(p));

                    this.Metrics.ToList().ForEach(m => eventTelemetry.Metrics.Add(m));
                    eventTelemetry.Metrics.Add(string.Concat(_eventName, "_Duration"),
                        (DateTime.UtcNow - _startTime).TotalMilliseconds);

                    _client.TrackEvent(eventTelemetry);
                }

                // TODO: free unmanaged resources (unmanaged objects) and override a finalizer below.
                // TODO: set large fields to null.

                disposedValue = true;
            }
        }
開發者ID:genesissupsup,項目名稱:DesktopApplicationInsights,代碼行數:32,代碼來源:TimedTelemetryEvent.cs

示例2: button2_Click

 private void button2_Click(object sender, RoutedEventArgs e)
 {
     var ev = new EventTelemetry("button2");
     ev.Properties["click_time"] = DateTime.Now.ToString(CultureInfo.InvariantCulture.DateTimeFormat);
     tc.TrackEvent(ev);
     tc.Flush();
 }
開發者ID:daniel-kun,項目名稱:AppInsightsTutorial,代碼行數:7,代碼來源:MainWindow.xaml.cs

示例3: Emit

        /// <summary>
        /// Emit the provided log event to the sink.
        /// </summary>
        /// <param name="logEvent">The log event to write.</param>
        public void Emit(LogEvent logEvent)
        {
            var renderedMessage = logEvent.RenderMessage(_formatProvider);
            
            // take logEvent and use it for the corresponding ITelemetry counterpart
            if (logEvent.Exception != null)
            {
                var exceptionTelemetry = new ExceptionTelemetry(logEvent.Exception)
                {
                    SeverityLevel = logEvent.Level.ToSeverityLevel(),
                    HandledAt = ExceptionHandledAt.UserCode,
                    Timestamp = logEvent.Timestamp
                };
                
                // write logEvent's .Properties to the AI one
                ForwardLogEventPropertiesToTelemetryProperties(exceptionTelemetry, logEvent, renderedMessage);

                _telemetryClient.TrackException(exceptionTelemetry);
            }
            else
            {
                var eventTelemetry = new EventTelemetry(logEvent.MessageTemplate.Text)
                {
                    Timestamp = logEvent.Timestamp
                };
                
                // write logEvent's .Properties to the AI one
                ForwardLogEventPropertiesToTelemetryProperties(eventTelemetry, logEvent, renderedMessage);
                
                _telemetryClient.TrackEvent(eventTelemetry);
            }
        }
開發者ID:alexvaluyskiy,項目名稱:serilog-sinks-applicationinsights,代碼行數:36,代碼來源:ApplicationInsightsSink.cs

示例4: SetsClientIpFromWcfContextOnOtherEvent

        public void SetsClientIpFromWcfContextOnOtherEvent()
        {
            const String originalIp = "10.12.32.12";
            const String newIp = "172.34.12.45";
            var context = new MockOperationContext();
            context.IncomingProperties.Add(
                RemoteEndpointMessageProperty.Name,
                new RemoteEndpointMessageProperty(originalIp, 7656));

            var initializer = new ClientIpTelemetryInitializer();

            // initialize request with the original IP
            initializer.Initialize(context.Request, context);

            // replace IP so that we can tell
            // it is being picked up from the request
            // rather than the context
            context.IncomingProperties.Clear();
            context.IncomingProperties.Add(
                RemoteEndpointMessageProperty.Name,
                new RemoteEndpointMessageProperty(newIp, 7656));

            var telemetry = new EventTelemetry("myevent");
            initializer.Initialize(telemetry, context);

            Assert.AreEqual(originalIp, telemetry.Context.Location.Ip);
        }
開發者ID:xornand,項目名稱:ApplicationInsights-SDK-Labs,代碼行數:27,代碼來源:ClientIpTelemetryInitializerTests.cs

示例5: InitializeSetsDateTime

        public void InitializeSetsDateTime()
        {
            EventTelemetry telemetry = new EventTelemetry("TestEvent");

            new TelemetryClient().Initialize(telemetry);

            Assert.True(telemetry.Timestamp != default(DateTimeOffset));
        }
開發者ID:ZeoAlliance,項目名稱:ApplicationInsights-dotnet,代碼行數:8,代碼來源:TelemetryClientTest.cs

示例6: ReportEvent

 /// <summary>
 /// Reports an event with a string data to the telemetry system.
 /// </summary>
 /// <param name="eventName"></param>
 public void ReportEvent(object component, string eventName, string data)
 {
     TelemetryClient client = new TelemetryClient();
     EventTelemetry eventT = new EventTelemetry();
     eventT.Name = component.GetType().Name + ":" + eventName;
     eventT.Properties.Add("data", data);
     client.TrackEvent(eventName);
 }
開發者ID:Arthur-Lee,項目名稱:Baconit,代碼行數:12,代碼來源:TelemetryManager.cs

示例7: SerializeWritesNullValuesAsExpectedByEndpoint

        public void SerializeWritesNullValuesAsExpectedByEndpoint()
        {
            EventTelemetry original = new EventTelemetry();
            original.Name = null;
            ((ITelemetry)original).Sanitize();
            var item = TelemetryItemTestHelper.SerializeDeserializeTelemetryItem<EventTelemetry, DataPlatformModel.EventData>(original);

            Assert.Equal(2, item.Data.BaseData.Ver);
        }
開發者ID:Assaf-Neufeld,項目名稱:ApplicationInsights-dotnet,代碼行數:9,代碼來源:EventTelemetryTest.cs

示例8: EventTelemetryMessage

 public EventTelemetryMessage(EventTelemetry telemetry)
 {
     this.Time = telemetry.Timestamp.DateTime;
     this.Name = telemetry.Name;
     this.Details = null;
     this.Properties = telemetry.Properties.Count > 0 ? telemetry.Properties : null;
     this.Type = "Event";
     this.Context = telemetry.Context;
 }
開發者ID:Glimpse,項目名稱:Glimpse.ApplicationInsights,代碼行數:9,代碼來源:EventTelemetryMessage.cs

示例9: InitializeSetsLocationIpToUserHostAddressIfNoHeadersInRequest

        public void InitializeSetsLocationIpToUserHostAddressIfNoHeadersInRequest()
        {
            var module = new TestableClientIpHeaderTelemetryInitializer();
            var telemetry = new EventTelemetry();

            module.Initialize(telemetry);

            Assert.AreEqual("127.0.0.1", telemetry.Context.Location.Ip);
        }
開發者ID:gregjhogan,項目名稱:ApplicationInsights-server-dotnet,代碼行數:9,代碼來源:ClientIpHeaderTelemetryModuleTest.cs

示例10: EventTelemetryHasCorrectValueOfSamplingPercentageAfterSerialization

        public void EventTelemetryHasCorrectValueOfSamplingPercentageAfterSerialization()
        {
            var telemetry = new EventTelemetry("my event");
            ((ISupportSampling)telemetry).SamplingPercentage = 10;

            var item = TelemetryItemTestHelper.SerializeDeserializeTelemetryItem<EventTelemetry, DataPlatformModel.EventData>(telemetry);

            Assert.Equal(10, item.SampleRate);
        }
開發者ID:ZeoAlliance,項目名稱:ApplicationInsights-dotnet,代碼行數:9,代碼來源:EventTelemetryTest.cs

示例11: HandleEvent

		public void HandleEvent(string eventName)
		{
			var interval = _random.Next(1, 10);
			var ev = new EventTelemetry(eventName) {Timestamp = DateTimeOffset.UtcNow};
			ev.Metrics.Add("ResponseTime", interval);
			_telemetryClient.TrackEvent(ev);

			Console.WriteLine("Event - {0}", eventName);
		}
開發者ID:toddmeinershagen,項目名稱:Demo.ApplicationInsights,代碼行數:9,代碼來源:Program.cs

示例12: InitializeGetsFirstIpIfHeaderHasSeveralIps

        public void InitializeGetsFirstIpIfHeaderHasSeveralIps()
        {
            var dictionary = new Dictionary<string, string> { { "X-Forwarded-For", "1.2.3.4, 2.3.4.5,3.4.5.6" } };
            var module = new TestableClientIpHeaderTelemetryInitializer(dictionary);
            var telemetry = new EventTelemetry();

            module.Initialize(telemetry);

            Assert.AreEqual("1.2.3.4", telemetry.Context.Location.Ip);
        }
開發者ID:Microsoft,項目名稱:ApplicationInsights-dotnet-server,代碼行數:10,代碼來源:ClientIpHeaderTelemetryModuleTest.cs

示例13: SamplingScoreIsRandomIfUserIdAndOperationIdAreNotPresent

        public void SamplingScoreIsRandomIfUserIdAndOperationIdAreNotPresent()
        {
            var eventTelemetry = new EventTelemetry();
            var traceTelemetry = new TraceTelemetry();

            var eventTelemetrySamplingScore = SamplingScoreGenerator.GetSamplingScore(eventTelemetry);
            var traceTelemetrySamplingScore = SamplingScoreGenerator.GetSamplingScore(traceTelemetry);

            Assert.NotEqual(eventTelemetrySamplingScore, traceTelemetrySamplingScore);
        }
開發者ID:jwChung,項目名稱:ApplicationInsights-dotnet,代碼行數:10,代碼來源:SamplingScoreGeneratorTest.cs

示例14: ContextInitializerDoesNotOverrideMachineName

        public void ContextInitializerDoesNotOverrideMachineName()
        {
            var telemetryItem = new EventTelemetry();
            var source = new DomainNameRoleInstanceTelemetryInitializer();
            telemetryItem.Context.Cloud.RoleInstance = "Test";

            source.Initialize(telemetryItem);

            Assert.Equal("Test", telemetryItem.Context.Cloud.RoleInstance);
        }
開發者ID:gregjhogan,項目名稱:ApplicationInsights-server-dotnet,代碼行數:10,代碼來源:DomainNameRoleInstanceTelemetryInitializerTest.cs

示例15: InitializeSetsTelemetryOperationNameToMethodAndPath

        public void InitializeSetsTelemetryOperationNameToMethodAndPath()
        {
            var contextAccessor = HttpContextAccessorHelper.CreateHttpContextAccessor(new RequestTelemetry(), null);

            var initializer = new OperationNameTelemetryInitializer(contextAccessor, new DiagnosticListener(TestListenerName));

            var telemetry = new EventTelemetry();
            initializer.Initialize(telemetry);

            Assert.Equal("GET /Test", telemetry.Context.Operation.Name);
        }
開發者ID:jango2015,項目名稱:ApplicationInsights-aspnet5,代碼行數:11,代碼來源:OperationNameTelemetryInitializerTests.cs


注:本文中的Microsoft.ApplicationInsights.DataContracts.EventTelemetry類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。