@@ -349,13 +349,11 @@ The following script uses the [Azure Monitor Ingestion client library for .NET](
349
349
350
350
2. Replace the variables in the following sample code with values from your DCE and DCR. You may also want to replace the sample data with your own.
351
351
352
-
353
-
354
352
```csharp
355
353
// Initialize variables
356
- var endpoint = new Uri("https://logs-ingestion-rzmk.eastus2-1.ingest.monitor.azure.com"; );
357
- var ruleId = "dcr-00000000000000000000000000000000 ";
358
- var streamName = "Custom-MyTableRawData ";
354
+ var endpoint = new Uri("<data_collection_endpoint_uri>" );
355
+ var ruleId = "<data_collection_rule_id> ";
356
+ var streamName = "<stream_name> ";
359
357
360
358
// Create credential and client
361
359
var credential = new DefaultAzureCredential();
@@ -395,7 +393,44 @@ The following script uses the [Azure Monitor Ingestion client library for .NET](
395
393
});
396
394
397
395
// Upload logs
398
- Response response = client.Upload(ruleId, streamName, RequestContent.Create(data));
396
+ try
397
+ {
398
+ Response response = client.Upload(ruleId, streamName, RequestContent.Create(data));
399
+ }
400
+ catch (Exception ex)
401
+ {
402
+ Console.WriteLine("Upload failed with Exception " + ex.Message);
403
+ }
404
+
405
+ // Logs can also be uploaded in a List
406
+ var entries = new List<Object>();
407
+ for (int i = 0; i < 10; i++)
408
+ {
409
+ entries.Add(
410
+ new {
411
+ Time = recordingNow,
412
+ Computer = "Computer" + i.ToString(),
413
+ AdditionalContext = i
414
+ }
415
+ );
416
+ }
417
+
418
+ // Make the request
419
+ LogsUploadOptions options = new LogsUploadOptions();
420
+ bool isTriggered = false;
421
+ options.UploadFailed += Options_UploadFailed;
422
+ await client.UploadAsync(TestEnvironment.DCRImmutableId, TestEnvironment.StreamName, entries, options).ConfigureAwait(false);
423
+
424
+ Task Options_UploadFailed(LogsUploadFailedEventArgs e)
425
+ {
426
+ isTriggered = true;
427
+ Console.WriteLine(e.Exception);
428
+ foreach (var log in e.FailedLogs)
429
+ {
430
+ Console.WriteLine(log);
431
+ }
432
+ return Task.CompletedTask;
433
+ }
399
434
```
400
435
401
436
3. Execute the code, and the data should arrive in your Log Analytics workspace within a few minutes.
0 commit comments