@@ -87,41 +87,54 @@ The following script uses the [Azure Monitor Ingestion client library for .NET](
87
87
// Upload logs
88
88
try
89
89
{
90
- Response response = client.Upload(ruleId, streamName, RequestContent.Create(data));
90
+ var response = await client.UploadAsync(ruleId, streamName, RequestContent.Create(data)).ConfigureAwait(false);
91
+ if (response.IsError)
92
+ {
93
+ throw new Exception(response.ToString());
94
+ }
95
+
96
+ Console.WriteLine("Log upload completed using content upload");
91
97
}
92
98
catch (Exception ex)
93
99
{
94
- Console.WriteLine("Upload failed with Exception " + ex.Message);
100
+ Console.WriteLine("Upload failed with Exception: " + ex.Message);
95
101
}
96
102
97
103
// Logs can also be uploaded in a List
98
- var entries = new List<Object >();
104
+ var entries = new List<object >();
99
105
for (int i = 0; i < 10; i++)
100
106
{
101
- entries.Add(
102
- new {
103
- Time = recordingNow,
104
- Computer = "Computer" + i.ToString(),
105
- AdditionalContext = i
106
- }
107
- );
107
+ entries.Add(
108
+ new
109
+ {
110
+ Time = currentTime,
111
+ Computer = "Computer" + i.ToString(),
112
+ AdditionalContext = new
113
+ {
114
+ InstanceName = "user" + i.ToString(),
115
+ TimeZone = "Central Time",
116
+ Level = 3,
117
+ CounterName = "AppMetric1" + i.ToString(),
118
+ CounterValue = i
119
+ }
120
+ }
121
+ );
108
122
}
109
123
110
124
// Make the request
111
- LogsUploadOptions options = new LogsUploadOptions();
112
- bool isTriggered = false;
113
- options.UploadFailed += Options_UploadFailed;
114
- await client.UploadAsync(TestEnvironment.DCRImmutableId, TestEnvironment.StreamName, entries, options).ConfigureAwait(false);
125
+ try
126
+ {
127
+ var response = await client.UploadAsync(ruleId, streamName, entries).ConfigureAwait(false);
128
+ if (response.IsError)
129
+ {
130
+ throw new Exception(response.ToString());
131
+ }
115
132
116
- Task Options_UploadFailed(LogsUploadFailedEventArgs e)
133
+ Console.WriteLine("Log upload completed using list of entries");
134
+ }
135
+ catch (Exception ex)
117
136
{
118
- isTriggered = true;
119
- Console.WriteLine(e.Exception);
120
- foreach (var log in e.FailedLogs)
121
- {
122
- Console.WriteLine(log);
123
- }
124
- return Task.CompletedTask;
137
+ Console.WriteLine("Upload failed with Exception: " + ex.Message);
125
138
}
126
139
```
127
140
0 commit comments