示例#1
0
        public async Task InsertRowAsync(T row, CancellationToken cancellationToken = default)
        {
            using IKustoQueuedIngestClient ingestClient = KustoIngestFactory.CreateQueuedIngestClient(_connectionStringBuilder);

            string serializedData = JsonConvert.SerializeObject(row);

            byte[] serializedBytes = Encoding.UTF8.GetBytes(serializedData);

            using MemoryStream dataStream = new MemoryStream(serializedBytes);

            // IKustoQueuedIngestClient doesn't support cancellation at the moment. Update the line below if it does in the future.
            await ingestClient.IngestFromStreamAsync(dataStream, _ingestionProperties, leaveOpen : true);
        }
示例#2
0
        /// <summary>
        /// Saves the details of the <see cref="HttpResponseMessage"/> to
        /// </summary>
        /// <param name="monitorName"></param>
        /// <param name="httpResponse"></param>
        /// <returns></returns>
        public async Task ReportUrlAccessAsync(string monitorName, HttpResponseMessage httpResponse, CancellationToken cancellationToken = default)
        {
            HttpRequestLogEntry logEntry = new HttpRequestLogEntry()
            {
                MonitorName    = monitorName,
                EventTime      = DateTime.UtcNow,
                RequestedUrl   = httpResponse.RequestMessage.RequestUri.AbsoluteUri,
                HttpStatusCode = (int)httpResponse.StatusCode
            };

            KustoConnectionStringBuilder kcsb = new KustoConnectionStringBuilder($"https://ingest-{ServiceNameAndRegion}.kusto.windows.net")
                                                .WithAadManagedIdentity("system");

            using IKustoQueuedIngestClient ingestClient = KustoIngestFactory.CreateQueuedIngestClient(kcsb);
            KustoQueuedIngestionProperties ingestProps = new KustoQueuedIngestionProperties(DatabaseName, TableName)
            {
                ReportLevel      = IngestionReportLevel.FailuresOnly,
                ReportMethod     = IngestionReportMethod.Queue,
                IngestionMapping = new IngestionMapping()
                {
                    IngestionMappingKind = Kusto.Data.Ingestion.IngestionMappingKind.Json,
                    IngestionMappings    = HttpRequestLogColumnMapping
                },
                Format = DataSourceFormat.json
            };

            using MemoryStream memStream = new MemoryStream();
            using StreamWriter writer    = new StreamWriter(memStream);

            writer.WriteLine(JsonConvert.SerializeObject(logEntry));

            writer.Flush();
            memStream.Seek(0, SeekOrigin.Begin);

            // IKustoQueuedIngestClient doesn't support cancellation at the moment. Update the line below if it does in the future.
            await ingestClient.IngestFromStreamAsync(memStream, ingestProps, leaveOpen : true);
        }