如何使用C#mongo驱动程序跟踪mongo命令并编写命令进行记录
答案 0 :(得分:0)
使用MongoClientSettings如下创建MongoClient:
var mongoConnectionUrl = new MongoUrl(connectionString);
var mongoClientSettings = MongoClientSettings.FromUrl(mongoConnectionUrl);
mongoClientSettings.ClusterConfigurator = cb =>
{
cb.Subscribe<CommandStartedEvent>(e =>
{
logger.LogInformation($"{e.CommandName} - {e.Command.ToJson()}");
});
};
var client = new MongoClient(mongoClientSettings);