Files
TakeoutSaaS.TenantApi/src/Infrastructure/TakeoutSaaS.Infrastructure/Logs/Publishers/IdentityOperationLogPublisher.cs

28 lines
1015 B
C#
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
using MassTransit;
using Microsoft.Extensions.Logging;
using TakeoutSaaS.Application.Identity.Abstractions;
using TakeoutSaaS.Application.Identity.Events;
namespace TakeoutSaaS.Infrastructure.Logs.Publishers;
/// <summary>
/// 身份模块操作日志发布器(基于 MassTransit Outbox
/// </summary>
public sealed class IdentityOperationLogPublisher(
ILogger<IdentityOperationLogPublisher> logger,
IPublishEndpoint? publishEndpoint = null) : IIdentityOperationLogPublisher
{
/// <inheritdoc />
public Task PublishAsync(IdentityUserOperationLogMessage message, CancellationToken cancellationToken = default)
{
if (publishEndpoint is null)
{
logger.LogDebug("未配置 MassTransit已跳过操作日志消息发布{OperationType}", message.OperationType);
return Task.CompletedTask;
}
// 1. (空行后) 已配置 MassTransit 时正常发布消息
return publishEndpoint.Publish(message, cancellationToken);
}
}