你当前正在访问 Microsoft Azure Global Edition 技术文档网站。 如果需要访问由世纪互联运营的 Microsoft Azure 中国技术文档网站,请访问 https://docs.azure.cn。
LogsIngestionClient.UploadAsync 方法
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
重载
UploadAsync(String, String, RequestContent, String, RequestContext) |
[协议方法]用于使用数据收集规则直接引入数据的引入 API
|
UploadAsync<T>(String, String, IEnumerable<T>, LogsUploadOptions, CancellationToken) |
用于使用数据收集规则直接引入数据的引入 API。 |
UploadAsync(String, String, RequestContent, String, RequestContext)
- Source:
- LogsIngestionClient.cs
- Source:
- LogsIngestionClient.cs
[协议方法]用于使用数据收集规则直接引入数据的引入 API
- 此 协议方法 允许显式创建请求并处理高级方案的响应。
public virtual System.Threading.Tasks.Task<Azure.Response> UploadAsync(string ruleId, string streamName, Azure.Core.RequestContent content, string contentEncoding = default, Azure.RequestContext context = default);
abstract member UploadAsync : string * string * Azure.Core.RequestContent * string * Azure.RequestContext -> System.Threading.Tasks.Task<Azure.Response>
override this.UploadAsync : string * string * Azure.Core.RequestContent * string * Azure.RequestContext -> System.Threading.Tasks.Task<Azure.Response>
Public Overridable Function UploadAsync (ruleId As String, streamName As String, content As RequestContent, Optional contentEncoding As String = Nothing, Optional context As RequestContext = Nothing) As Task(Of Response)
参数
- ruleId
- String
数据收集规则资源的不可变 ID。
- streamName
- String
数据收集规则中定义的 streamDeclaration 名称。
- content
- RequestContent
要作为请求正文发送的内容。
- contentEncoding
- String
如果内容已 gzipped,则输入“gzip”。 默认行为是对所有输入进行 gzip。
- context
- RequestContext
请求上下文,可以基于每个调用替代客户端管道的默认行为。
返回
从服务返回的响应。
例外
ruleId
、streamName
或 content
为 null。
ruleId
或 streamName
是空字符串,预期为非空。
服务返回了非成功状态代码。
示例
此示例演示如何调用 UploadAsync。
Uri endpoint = new Uri("<endpoint>");
TokenCredential credential = new DefaultAzureCredential();
LogsIngestionClient client = new LogsIngestionClient(endpoint, credential);
using RequestContent content = RequestContent.Create(new object[]
{
new object()
});
Response response = await client.UploadAsync("<ruleId>", "<streamName>", content);
Console.WriteLine(response.Status);
此示例演示如何使用所有参数和请求内容调用 UploadAsync。
Uri endpoint = new Uri("<endpoint>");
TokenCredential credential = new DefaultAzureCredential();
LogsIngestionClient client = new LogsIngestionClient(endpoint, credential);
using RequestContent content = RequestContent.Create(new object[]
{
new object()
});
Response response = await client.UploadAsync("<ruleId>", "<streamName>", content, contentEncoding: "<contentEncoding>");
Console.WriteLine(response.Status);
注解
有关更多详细信息,请参阅错误响应代码和错误响应消息。
适用于
UploadAsync<T>(String, String, IEnumerable<T>, LogsUploadOptions, CancellationToken)
- Source:
- LogsIngestionClient.cs
- Source:
- LogsIngestionClient.cs
用于使用数据收集规则直接引入数据的引入 API。
public virtual System.Threading.Tasks.Task<Azure.Response> UploadAsync<T>(string ruleId, string streamName, System.Collections.Generic.IEnumerable<T> logs, Azure.Monitor.Ingestion.LogsUploadOptions options = default, System.Threading.CancellationToken cancellationToken = default);
abstract member UploadAsync : string * string * seq<'T> * Azure.Monitor.Ingestion.LogsUploadOptions * System.Threading.CancellationToken -> System.Threading.Tasks.Task<Azure.Response>
override this.UploadAsync : string * string * seq<'T> * Azure.Monitor.Ingestion.LogsUploadOptions * System.Threading.CancellationToken -> System.Threading.Tasks.Task<Azure.Response>
Public Overridable Function UploadAsync(Of T) (ruleId As String, streamName As String, logs As IEnumerable(Of T), Optional options As LogsUploadOptions = Nothing, Optional cancellationToken As CancellationToken = Nothing) As Task(Of Response)
类型参数
- T
参数
- ruleId
- String
数据收集规则资源的不可变 ID。
- streamName
- String
数据收集规则中定义的 streamDeclaration 名称。
- logs
- IEnumerable<T>
要作为请求正文发送的内容。 请求正文架构的详细信息,请参阅下面的“备注”部分。
- options
- LogsUploadOptions
用于配置将日志上传到 Azure Monitor 的请求的选项模型。
- cancellationToken
- CancellationToken
返回
从服务返回的响应。
例外
ruleId
、streamName
或 logs
为 null。
ruleId
或 streamName
是空字符串,预期为非空。
服务返回了非成功状态代码。
示例
此示例演示如何使用所需的参数和请求内容调用 Upload。
var credential = new DefaultAzureCredential();
var endpoint = new Uri("<https://my-account-name.azure.com>");
var client = new LogsIngestionClient(endpoint, credential);
var data = new[] {
new {}
};
Response response = client.Upload("<ruleId>", "<streamName>", data);
Console.WriteLine(response.Status);
注解
有关更多详细信息,请参阅错误响应代码和错误响应消息。