private void EnableRemoteTelemetryIfNeeded(string logFilePath) { if (!_enableRemoteTelemetry) { return; } if (_kustoUploader == null) { _logger.Warning ( "Remote telemetry flag is enabled but no Kusto connection string was found in environment variable '{0}'", KustoConnectionStringEnvVarName ); return; } _csvFileLog = new CsvFileLog ( logFilePath: logFilePath + TmpCsvLogFileExt, serviceName: ServiceName, schema: KustoTableCsvSchema, severity: _fileLogSeverity, maxFileSize: _csvLogMaxFileSize ); // Every time a log file written to disk and closed, we rename it and upload it to Kusto. // The last log file will be produced when _csvFileLog is disposed, so _kustUploader better // not be disposed before _csvFileLog. _csvFileLog.OnLogFileProduced += (path) => { string newPath = Path.ChangeExtension(path, CsvLogFileExt); File.Move(path, newPath); _kustoUploader.PostFileForUpload(newPath, _csvFileLog.BuildId); }; _logger.AddLog(_csvFileLog); _logger.Always("Remote telemetry enabled"); }
private void EnableRemoteTelemetryIfNeeded(string logFilePath) { if (!_enableRemoteTelemetry) { return; } var kustoConnectionString = Environment.GetEnvironmentVariable(KustoConnectionStringEnvVarName); if (string.IsNullOrWhiteSpace(kustoConnectionString)) { _logger.Warning ( "Remote telemetry flag is enabled but no Kusto connection string was found in environment variable '{0}'", KustoConnectionStringEnvVarName ); return; } _csvFileLog = new CsvFileLog ( logFilePath: logFilePath + TmpCsvLogFileExt, serviceName: ServiceName, schema: KustoTableCsvSchema, renderConstColums: false, severity: _fileLogSeverity, maxFileSize: _csvLogMaxFileSize ); var indexedColumns = _csvFileLog.FileSchema.Select((col, idx) => new CsvColumnMapping { ColumnName = col.ToString(), Ordinal = idx }); var constColumns = _csvFileLog.ConstSchema.Select(col => new CsvColumnMapping { ColumnName = col.ToString(), ConstValue = _csvFileLog.RenderConstColumn(col) }); var csvMapping = indexedColumns.Concat(constColumns).ToArray(); var csvMappingStr = string.Join("", csvMapping.Select(col => $"{Environment.NewLine} Name: '{col.ColumnName}', ConstValue: '{col.ConstValue}', Ordinal: {col.Ordinal}")); _logger.Always("Using csv mapping:{0}", csvMappingStr); _kustoUploader = new KustoUploader ( kustoConnectionString, database: KustoDatabase, table: KustoTable, csvMapping: csvMapping, deleteFilesOnSuccess: true, checkForIngestionErrors: true, log: _consoleLog ); // Every time a log file written to disk and closed, we rename it and upload it to Kusto. // The last log file will be produced when _csvFileLog is disposed, so _kustUploader better // not be disposed before _csvFileLog. _csvFileLog.OnLogFileProduced += (path) => { string newPath = Path.ChangeExtension(path, CsvLogFileExt); File.Move(path, newPath); _kustoUploader.PostFileForUpload(newPath, _csvFileLog.BuildId); }; _logger.AddLog(_csvFileLog); _logger.Always("Remote telemetry enabled"); }