private static void UploadLogs(string profile, TelemetryConfiguration telemetryConfiguration, string logFilePath, string metricsFilePath, string logsPath, bool enabledDefaultCredentials = false) { if (!string.IsNullOrEmpty(profile) || enabledDefaultCredentials) { var isSuccess = false; telemetryConfiguration.LogFilePath = logFilePath; telemetryConfiguration.MetricsFilePath = metricsFilePath; telemetryConfiguration.LogsPath = logsPath; telemetryConfiguration.Suffix = new List <string> { ".log", ".metrics" }; if (TelemetryClientFactory.TryGetClient(profile, telemetryConfiguration, out ITelemetryClient client, enabledDefaultCredentials)) { isSuccess = Uploader.Upload(telemetryConfiguration, profile, client); } else { Log.Logger.Error("Invalid Credentials."); } if (!isSuccess) { Log.Logger.Error("Upload Metrics/Logs Failed!"); } else { Log.Logger.Information("Upload Metrics/Logs Success!"); } }
public void Upload_Empty_File_Default_Creds_Returns_Success_Status() { var profile = "DEFAULT"; var roamingFolder = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData); var logs = Path.Combine(roamingFolder, "Porting Assistant for .NET", "logs"); var teleConfig = new TelemetryConfiguration { InvokeUrl = "https://8q2itpfg51.execute-api.us-east-1.amazonaws.com/beta", Region = "us-east-1", LogsPath = logs, ServiceName = "appmodernization-beta", Description = "Test", LogFilePath = Path.Combine(logs, "portingAssistant-client-cli-test.log"), MetricsFilePath = Path.Combine(logs, "portingAssistant-client-cli-test.metrics"), Suffix = new List <string> { ".log", ".metrics" } }; bool actualSuccessStatus = false; if (TelemetryClientFactory.TryGetClient(profile, teleConfig, out ITelemetryClient client, true)) { actualSuccessStatus = Uploader.Upload(teleConfig, profile, client); } Assert.IsTrue(actualSuccessStatus); }
public void Ctor_CreatesObjectWithExpectedProperties() { const string expectedInstrumentationKey = "My key"; string expectedVersion = OSHelpers.GetVersion(); TelemetryClient client = TelemetryClientFactory.GetClient(expectedInstrumentationKey); Assert.AreEqual(expectedInstrumentationKey, client.InstrumentationKey); Assert.AreEqual(expectedVersion, client.Context.Device.OperatingSystem); Assert.AreEqual("undefined", client.Context.Cloud.RoleInstance); }
public async Task Next(Benchmark benchmark) { Console.WriteLine(TestCaseConfiguration.TelemetryClientType); benchmark.Context.TelemetryClient = TelemetryClientFactory.Create(TestCaseConfiguration.TelemetryClientType); // Create message capture context benchmark.Context.MessageCaptureContext = new MessageCaptureContext( BenchmarkConfiguration.MessageCount, benchmark.Context.TelemetryClient ); await benchmark.SetNext(new CreateTestCase()); }
public void Should_ThrowErrorWhenTryingToCreateUndefinedTelemetryClient() { Assert.Throws <ArgumentOutOfRangeException>(() => TelemetryClientFactory.Create(0)); }
public void Should_CreateTelemetryClientOfTypeInMemoryTelemetryClient() { var testCase = TelemetryClientFactory.Create(TelemetryClientType.InMemory); Assert.IsType <InMemoryTelemetryClient>(testCase); }