public async void LoadDataToKusto(string sinkName, List <LogRecordSentinel> list) { try { var data = new EnumerableDataReader <LogRecordSentinel>(list, eventLogFields); var client = KustoIngestClients.FirstOrDefault(x => x.Name.Equals(sinkName)); await client?.IKustoIngestClient.IngestFromDataReaderAsync(data, client.KustoIngestionProperties); } catch (Exception ex) { Console.WriteLine($"LoadToLogFileKusto error: {ex}"); } }
public void LoadMetricsToKusto(string sinkName, List <SentinelCostMetric> list) { try { var data = new EnumerableDataReader <SentinelCostMetric>(list, sentinelCostMetricFields); var client = KustoIngestClients.FirstOrDefault(x => x.Name.Equals(sinkName)); client?.IKustoIngestClient.IngestFromDataReader(data, client.KustoIngestionProperties); } catch (Exception ex) { Console.WriteLine($"LoadToLogFileKusto error: {ex}"); } }
/// <summary>Intializes the logging configuration.</summary> /// <returns>A value indicating whether the Trace2Kusto configuration has changed</returns> public bool InitializeLoggingConfiguration() { // Determine the Environment JSON file to load, build, parse and instantiate DirectoryInfo dir_info = new DirectoryInfo(ApplicationPath); var builder = new ConfigurationBuilder() .SetBasePath(dir_info.FullName) .AddJsonFile($"appsettings.json"); Configuration = builder.Build(); ServiceKeyVaultInfo = Configuration.GetSection("KeyVaultInfo").Get <KeyVaultInfo>(); ServiceEventSinkInfos = Configuration.GetSection("EventSinkInfo").Get <List <EventSinkInfo> >(); this.KeyVault = new KeyVault(ServiceKeyVaultInfo); // Initialize KustoClients foreach (EventSinkInfo serviceEventSinkInfo in ServiceEventSinkInfos) { var kcsb = new KustoConnectionStringBuilder(serviceEventSinkInfo.Settings.EndpointUrl) { InitialCatalog = serviceEventSinkInfo.Settings.Database, FederatedSecurity = true }; string azureActiveDirectoryAppId = serviceEventSinkInfo.Settings.SinkId; string azureActiveDirectoryAppKey = KeyVault.GetSecret(serviceEventSinkInfo.Settings.SinkSecretKey); Console.WriteLine($"Create Kusto Client: {serviceEventSinkInfo.SinkAlias}"); // Create the Event Log Ingest client var client = new KustoIngestClient { IKustoIngestClient = GetKustoIngestClient(azureActiveDirectoryAppId, azureActiveDirectoryAppKey, serviceEventSinkInfo), KustoIngestionProperties = new KustoIngestionProperties(kcsb.InitialCatalog, serviceEventSinkInfo.Settings.Table), Name = serviceEventSinkInfo.SinkAlias }; KustoIngestClients.Add(client); } return(true); }