0

我已将 Azure Web 应用程序配置为通过此链接将日志发送到 Azure blob 存储。这按预期工作。

接下来,我想将事件 ID 和一些其他信息(IP 地址等)添加到日志中。有一种方法可以格式化控制台日志(链接),但我找不到对 Azure blob 日志执行相同操作的方法。是不支持的东西还是我忽略了一些东西?

PS - 我不想使用 Serilog。

4

1 回答 1

0

我们也可以在 azure blob 日志中写入自定义事件详细信息,

我想在日志中添加事件 ID 和其他一些信息(IP 地址等)。

每个日志都可以指定一个事件 ID

[HttpGet("{id}")]
public async Task<ActionResult<TodoItemDTO>> GetTodoItem(long id)
{
    _logger.LogInformation(MyLogEvents.GetItem, "Getting item {Id}", id);
var todoItem = await _context.TodoItems.FindAsync(id);

if (todoItem == null)
{
    _logger.LogWarning(MyLogEvents.GetItemNotFound, "Get({Id}) NOT FOUND", id);
    return NotFound();
}

return ItemToDTO(todoItem);

}

笔记:

  1. 日志提供者可以将事件 ID 存储在 ID 字段中、日志消息中,或者根本不存储;允许对 ID 进行过滤。
  2. 调试提供程序不显示事件 ID

每个日志 API 使用一个消息模板,其中包含为其提供参数的占位符。使用占位符的名称,而不是数字。

[HttpGet("{id}")]
public async Task<ActionResult<TodoItemDTO>> GetTodoItem(long id)
{
    _logger.LogInformation(MyLogEvents.GetItem, "Getting item {Id}", id);
var todoItem = await _context.TodoItems.FindAsync(id);

if (todoItem == null)
{
    _logger.LogWarning(MyLogEvents.GetItemNotFound, "Get({Id}) NOT FOUND", id);
    return NotFound();
}

return ItemToDTO(todoItem);

}

有关更多详细信息,请参阅Microsoft 文档AzureBlobStorageEventSchema

于 2021-09-13T10:34:18.927 回答