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


C# TelemetryClient.Track方法代码示例

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


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

示例1: TrackWritesTelemetryToDebugOutputIfIKeyNotEmpty

        public void TrackWritesTelemetryToDebugOutputIfIKeyNotEmpty()
        {
            string actualMessage = null;
            var debugOutput = new StubDebugOutput
            {
                OnWriteLine = message => actualMessage = message,
                OnIsAttached = () => true,
            };

            PlatformSingleton.Current = new StubPlatform { OnGetDebugOutput = () => debugOutput };
            var channel = new StubTelemetryChannel { DeveloperMode = true };
            var configuration = new TelemetryConfiguration
            {
                TelemetryChannel = channel,
                InstrumentationKey = "123"

            };
            var client = new TelemetryClient(configuration);

            client.Track(new StubTelemetry());

            Assert.True(actualMessage.StartsWith("Application Insights Telemetry: "));
            PlatformSingleton.Current = null;
        }
开发者ID:ZeoAlliance,项目名称:ApplicationInsights-dotnet,代码行数:24,代码来源:TelemetryClientTest.cs

示例2: TrackAddsDeveloperModeCustomPropertyWhenDeveloperModeIsTrue

        public void TrackAddsDeveloperModeCustomPropertyWhenDeveloperModeIsTrue()
        {
            ITelemetry sentTelemetry = null;
            var channel = new StubTelemetryChannel
            {
                OnSend = telemetry => sentTelemetry = telemetry,
                DeveloperMode = true
            };
            var configuration = new TelemetryConfiguration
            {
                TelemetryChannel = channel,
                InstrumentationKey = "Test key"
            };
            var client = new TelemetryClient(configuration);

            client.Track(new StubTelemetry());

            Assert.Equal("true", ((ISupportProperties)sentTelemetry).Properties["DeveloperMode"]);
        }
开发者ID:ZeoAlliance,项目名称:ApplicationInsights-dotnet,代码行数:19,代码来源:TelemetryClientTest.cs

示例3: TrackLogsDiagnosticsMessageOnExceptionsDuringTelemetryIntializersInitialize

        public void TrackLogsDiagnosticsMessageOnExceptionsDuringTelemetryIntializersInitialize()
        {
            using (var listener = new TestEventListener())
            {
                listener.EnableEvents(CoreEventSource.Log, EventLevel.Error);

                var configuration = new TelemetryConfiguration { InstrumentationKey = "Test key", TelemetryChannel = new StubTelemetryChannel() };
                var telemetryInitializer = new StubTelemetryInitializer();
                var exceptionMessage = "Test exception message";
                telemetryInitializer.OnInitialize = item => { throw new Exception(exceptionMessage); };
                configuration.TelemetryInitializers.Add(telemetryInitializer);

                var client = new TelemetryClient(configuration);
                client.Track(new StubTelemetry());

                var exceptionExplanation = "Exception while initializing " + typeof(StubTelemetryInitializer).FullName;
                var diagnosticsMessage = (string)listener.Messages.First().Payload[0];
                Assert.Contains(exceptionExplanation, diagnosticsMessage, StringComparison.OrdinalIgnoreCase);
                Assert.Contains(exceptionMessage, diagnosticsMessage, StringComparison.OrdinalIgnoreCase);
            }
        }
开发者ID:ZeoAlliance,项目名称:ApplicationInsights-dotnet,代码行数:21,代码来源:TelemetryClientTest.cs

示例4: TrackRespectsInstrumentaitonKeySetByTelemetryInitializer

        public void TrackRespectsInstrumentaitonKeySetByTelemetryInitializer()
        {
            var sentTelemetry = new List<ITelemetry>();
            var channel = new StubTelemetryChannel { OnSend = t => sentTelemetry.Add(t) };
            var configuration = new TelemetryConfiguration
            {
                // no instrumentation key set here
                TelemetryChannel = channel
            };

            var initializedTelemetry = new List<ITelemetry>();
            var telemetryInitializer = new StubTelemetryInitializer();
            telemetryInitializer.OnInitialize = item =>
            {
                item.Context.InstrumentationKey = "Foo";
                initializedTelemetry.Add(item);
            };

            configuration.TelemetryInitializers.Add(telemetryInitializer);

            var client = new TelemetryClient(configuration);

            var telemetry = new StubTelemetry();
            client.Track(telemetry);

            Assert.Equal(1, sentTelemetry.Count);
            Assert.Equal(1, initializedTelemetry.Count);
        }
开发者ID:ZeoAlliance,项目名称:ApplicationInsights-dotnet,代码行数:28,代码来源:TelemetryClientTest.cs

示例5: TrackDoesNotTryAddingDeveloperModeCustomPropertyWhenTelemetryDoesNotSupportCustomProperties

        public void TrackDoesNotTryAddingDeveloperModeCustomPropertyWhenTelemetryDoesNotSupportCustomProperties()
        {
            var channel = new StubTelemetryChannel { DeveloperMode = true };
            var configuration = new TelemetryConfiguration { TelemetryChannel = channel, InstrumentationKey = "Test Key" };
            var client = new TelemetryClient(configuration);

            Assert.DoesNotThrow(() => client.Track(new SessionStateTelemetry()));
        }
开发者ID:ZeoAlliance,项目名称:ApplicationInsights-dotnet,代码行数:8,代码来源:TelemetryClientTest.cs

示例6: TrackDoesNotWriteTelemetryToDebugOutputIfNotInDeveloperMode

        public void TrackDoesNotWriteTelemetryToDebugOutputIfNotInDeveloperMode()
        {
            string actualMessage = null;
            var debugOutput = new StubDebugOutput { OnWriteLine = message => actualMessage = message };
            PlatformSingleton.Current = new StubPlatform { OnGetDebugOutput = () => debugOutput };
            var channel = new StubTelemetryChannel();
            var configuration = new TelemetryConfiguration
            {
                TelemetryChannel = channel,
                InstrumentationKey = "Test key"
            };
            var client = new TelemetryClient(configuration);

            client.Track(new StubTelemetry());
            PlatformSingleton.Current = null;
            Assert.Null(actualMessage);
        }
开发者ID:ZeoAlliance,项目名称:ApplicationInsights-dotnet,代码行数:17,代码来源:TelemetryClientTest.cs

示例7: TrackDoesNotSendDataWhenTelemetryIsDisabled

        public void TrackDoesNotSendDataWhenTelemetryIsDisabled()
        {
            var sentTelemetry = new List<ITelemetry>();
            var channel = new StubTelemetryChannel { OnSend = t => sentTelemetry.Add(t) };
            var configuration = new TelemetryConfiguration { DisableTelemetry = true , TelemetryChannel = channel };

            var client = new TelemetryClient(configuration) {};

            client.Track(new StubTelemetry());

            Assert.Equal(0, sentTelemetry.Count);
        }
开发者ID:ZeoAlliance,项目名称:ApplicationInsights-dotnet,代码行数:12,代码来源:TelemetryClientTest.cs

示例8: TrackDoesNotThrowExceptionsDuringTelemetryIntializersInitialize

 public void TrackDoesNotThrowExceptionsDuringTelemetryIntializersInitialize()
 {
     var configuration = new TelemetryConfiguration { InstrumentationKey = "Test key", TelemetryChannel = new StubTelemetryChannel() };
     var telemetryInitializer = new StubTelemetryInitializer();
     telemetryInitializer.OnInitialize = item => { throw new Exception(); };
     configuration.TelemetryInitializers.Add(telemetryInitializer);
     var client = new TelemetryClient(configuration);
     Assert.DoesNotThrow(() => client.Track(new StubTelemetry()));
 }
开发者ID:ZeoAlliance,项目名称:ApplicationInsights-dotnet,代码行数:9,代码来源:TelemetryClientTest.cs

示例9: TrackDoesNotOverrideSdkVersion

        public void TrackDoesNotOverrideSdkVersion()
        {
            var configuration = new TelemetryConfiguration { TelemetryChannel = new StubTelemetryChannel(), InstrumentationKey = Guid.NewGuid().ToString() };
            var client = new TelemetryClient(configuration);

            client.Context.InstrumentationKey = "Test";
            EventTelemetry eventTelemetry = new EventTelemetry("test");
            eventTelemetry.Context.Internal.SdkVersion = "test";
            client.Track(eventTelemetry);

            Assert.Equal("test", eventTelemetry.Context.Internal.SdkVersion);
        }
开发者ID:ZeoAlliance,项目名称:ApplicationInsights-dotnet,代码行数:12,代码来源:TelemetryClientTest.cs

示例10: TrackDoesNotOverwriteTelemetryPropertiesWithClientPropertiesBecauseExplicitlySetValuesTakePrecedence

        public void TrackDoesNotOverwriteTelemetryPropertiesWithClientPropertiesBecauseExplicitlySetValuesTakePrecedence()
        {
            var configuration = new TelemetryConfiguration { TelemetryChannel = new StubTelemetryChannel() };
            var client = new TelemetryClient(configuration);
            client.Context.Properties["TestProperty"] = "ClientValue";
            client.Context.InstrumentationKey = "Test Key";

            var telemetry = new StubTelemetry { Properties = { { "TestProperty", "TelemetryValue" } } };
            client.Track(telemetry);

            Assert.Equal("TelemetryValue", telemetry.Properties["TestProperty"]);
        }
开发者ID:ZeoAlliance,项目名称:ApplicationInsights-dotnet,代码行数:12,代码来源:TelemetryClientTest.cs

示例11: TrackDoesNotAddDeveloperModeCustomPropertyIfDeveloperModeIsSetToFalse

        public void TrackDoesNotAddDeveloperModeCustomPropertyIfDeveloperModeIsSetToFalse()
        {
            ITelemetry sentTelemetry = null;
            var channel = new StubTelemetryChannel
            {
                OnSend = telemetry => sentTelemetry = telemetry,
                DeveloperMode = false
            };
            var configuration = new TelemetryConfiguration
            {
                TelemetryChannel = channel,
                InstrumentationKey = "Test key"
            };
            var client = new TelemetryClient(configuration);

            client.Track(new StubTelemetry());

            Assert.False(((ISupportProperties)sentTelemetry).Properties.ContainsKey("DeveloperMode"));
        }
开发者ID:ZeoAlliance,项目名称:ApplicationInsights-dotnet,代码行数:19,代码来源:TelemetryClientTest.cs

示例12: StubTelemetryInitializer

        public void TrackCopiesPropertiesFromClientToTelemetryBeforeInvokingInitializersBecauseExplicitlySetValuesTakePrecedence()
        {
            const string PropertyName = "TestProperty";

            string valueInInitializer = null;
            var initializer = new StubTelemetryInitializer();
            initializer.OnInitialize = telemetry => valueInInitializer = ((ISupportProperties)telemetry).Properties[PropertyName];

            var configuration = new TelemetryConfiguration { TelemetryChannel = new StubTelemetryChannel(), TelemetryInitializers = { initializer } };

            var client = new TelemetryClient(configuration);
            client.Context.Properties[PropertyName] = "ClientValue";
            client.Context.InstrumentationKey = "Test Key";

            client.Track(new StubTelemetry());

            Assert.Equal(client.Context.Properties[PropertyName], valueInInitializer);
        }
开发者ID:ZeoAlliance,项目名称:ApplicationInsights-dotnet,代码行数:18,代码来源:TelemetryClientTest.cs

示例13: TrackCopiesPropertiesFromClientToTelemetry

        public void TrackCopiesPropertiesFromClientToTelemetry()
        {
            var configuration = new TelemetryConfiguration { TelemetryChannel = new StubTelemetryChannel() };
            var client = new TelemetryClient(configuration);
            client.Context.Properties["TestProperty"] = "TestValue";
            client.Context.InstrumentationKey = "Test Key";

            var telemetry = new StubTelemetry();
            client.Track(telemetry);

            Assert.Equal(client.Context.Properties.ToArray(), telemetry.Properties.ToArray());
        }
开发者ID:ZeoAlliance,项目名称:ApplicationInsights-dotnet,代码行数:12,代码来源:TelemetryClientTest.cs

示例14: TrackAddsTimestampWhenMissing

        public void TrackAddsTimestampWhenMissing()
        {
            ITelemetry sentTelemetry = null;
            var channel = new StubTelemetryChannel
            {
                OnSend = telemetry => sentTelemetry = telemetry
            };
            var configuration = new TelemetryConfiguration
            {
                TelemetryChannel = channel,
                InstrumentationKey = "Test key"
            };
            var client = new TelemetryClient(configuration);

            client.Track(new StubTelemetry());

            Assert.NotEqual(DateTimeOffset.MinValue, sentTelemetry.Timestamp);
        }
开发者ID:ZeoAlliance,项目名称:ApplicationInsights-dotnet,代码行数:18,代码来源:TelemetryClientTest.cs

示例15: TrackAddsSdkVerionByDefault

        public void TrackAddsSdkVerionByDefault()
        {
            var configuration = new TelemetryConfiguration { TelemetryChannel = new StubTelemetryChannel(), InstrumentationKey = Guid.NewGuid().ToString() };
            var client = new TelemetryClient(configuration);

            client.Context.InstrumentationKey = "Test";
            EventTelemetry eventTelemetry = new EventTelemetry("test");
            client.Track(eventTelemetry);

            Assert.StartsWith("dotnet: ", eventTelemetry.Context.Internal.SdkVersion);
        }
开发者ID:ZeoAlliance,项目名称:ApplicationInsights-dotnet,代码行数:11,代码来源:TelemetryClientTest.cs


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