public ApplicationInsightsLogger(string instrumentationKey, IApplicationController applicationController)
        {
            InstrumentationKey    = instrumentationKey;
            ApplicationController = applicationController;
            SessionId             = Guid.NewGuid().ToString();
            AnonymousString       = "Anonymous " + StringEncryptor.HashString(UserName);

            TelemetryConfiguration.Active.InstrumentationKey = InstrumentationKey;

            #if DEBUG
            IsDebugMode = true;
            #endif

            var telemetryConfiguration = new TelemetryConfiguration(InstrumentationKey);

            //this tells to promptly send data if debugging
            telemetryConfiguration.TelemetryChannel.DeveloperMode = IsDebugMode;
            //for when debuuging if want to send data uncomment this line
            //IsDebugMode = false;

            var tc = new TelemetryClient(telemetryConfiguration);
            tc.InstrumentationKey             = InstrumentationKey;
            tc.Context.Cloud.RoleInstance     = ApplicationController.ApplicationName;
            tc.Context.User.UserAgent         = $"{ApplicationController.ApplicationName} {ApplicationController.Version}";
            tc.Context.User.Id                = string.Empty;
            tc.Context.Session.Id             = SessionId;
            tc.Context.Device.OperatingSystem = Environment.OSVersion.ToString();
            TelemetryClient = tc;
        }
예제 #2
0
        public void StringEncryptorHashStringTest()
        {
            const string initial = "THESTRING";
            var          hashed  = StringEncryptor.HashString(initial);

            Assert.IsFalse(hashed.Contains(initial));
        }