EasilyNET.Mongo.ConsoleDebug 3.24.613.115

There is a newer version of this package available.
See the version list below for details.
dotnet add package EasilyNET.Mongo.ConsoleDebug --version 3.24.613.115                
NuGet\Install-Package EasilyNET.Mongo.ConsoleDebug -Version 3.24.613.115                
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="EasilyNET.Mongo.ConsoleDebug" Version="3.24.613.115" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add EasilyNET.Mongo.ConsoleDebug --version 3.24.613.115                
#r "nuget: EasilyNET.Mongo.ConsoleDebug, 3.24.613.115"                
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install EasilyNET.Mongo.ConsoleDebug as a Cake Addin
#addin nuget:?package=EasilyNET.Mongo.ConsoleDebug&version=3.24.613.115

// Install EasilyNET.Mongo.ConsoleDebug as a Cake Tool
#tool nuget:?package=EasilyNET.Mongo.ConsoleDebug&version=3.24.613.115                

EasilyNET.Mongo.ConsoleDebug

常使用 EF 的小伙伴就应该能够知道,可以让 EF 生产的 SQL 语句输出到控制台,在开发的时候非常方便调试.<br/> 而 MongoDB 却没有这样的功能,所以产生了这个库,虽然不完美,但是能够解决一些开发过程中不方便排查问题的情况.

  • 最终效果类似如下:
 ╭───────────────────────────────Command────────────────────────────────╮╭──────────────────Calendar──────────────────╮
 │ {                                                                    ││                2023 August                 │
 │   "insert" : "mongo.test",                                           ││ ┌─────┬─────┬─────┬─────┬─────┬─────┬────┐ │
 │   "ordered" : true,                                                  ││ │ Sun │ Mon │ Tue │ Wed │ Thu │ Fri │ S… │ │
 │   "$db" : "test1",                                                   ││ ├─────┼─────┼─────┼─────┼─────┼─────┼────┤ │
 │   "lsid" : {                                                         ││ │     │     │ 1   │ 2   │ 3   │ 4   │ 5  │ │
 │     "id" : CSUUID("f12dd90d-2f58-4655-9bf2-cbce2d9bd2c4")            ││ │ 6   │ 7   │ 8   │ 9   │ 10  │ 11  │ 12 │ │
 │   },                                                                 ││ │ 13  │ 14  │ 15  │ 16  │ 17  │ 18  │ 19 │ │
 │   "documents" : [{                                                   ││ │ 20  │ 21  │ 22  │ 23* │ 24  │ 25  │ 26 │ │
 │       "_id" : ObjectId("64e57f266a1a63e69c52b9cb"),                  ││ │ 27  │ 28  │ 29  │ 30  │ 31  │     │    │ │
 │       "dateTime" : ISODate("2023-08-23T03:38:14.121Z"),              ││ │     │     │     │     │     │     │    │ │
 │       "timeSpan" : "00:00:50",                                       ││ └─────┴─────┴─────┴─────┴─────┴─────┴────┘ │
 │       "dateOnly" : "2023-08-23",                                     │╰────────────────────────────────────────────╯
 │       "timeOnly" : "11:38:14",                                       │╭────────────────────Info────────────────────╮
 │       "nullableDateOnly" : "2023-08-23",                             ││ {                                          │
 │       "nullableTimeOnly" : null                                      ││    "RequestId": 86,                        │
 │     }]                                                               ││    "Timestamp": "2023-08-23 03:38:14",     │
 │ }                                                                    ││    "Method": "insert",                     │
 │                                                                      ││    "DatabaseName": "test1",                │
 │                                                                      ││    "CollectionName": "mongo.test",         │
 │                                                                      ││    "ConnectionInfo": {                     │
 │                                                                      ││       "ClusterId": 1,                      │
 │                                                                      ││       "EndPoint": "127.0.0.1:27018"        │
 │                                                                      ││    }                                       │
 │                                                                      ││ }                                          │
 │                                                                      │╰────────────────────────────────────────────╯
 │                                                                      │╭───────────────Request Status───────────────╮
 │                                                                      ││ ┌───────────┬────────────────┬───────────┐ │
 │                                                                      ││ │ RequestId │      Time      │  Status   │ │
 │                                                                      ││ ├───────────┼────────────────┼───────────┤ │
 │                                                                      ││ │    86     │ 11:38:14.12640 │ Succeeded │ │
 │                                                                      ││ └───────────┴────────────────┴───────────┘ │
 │                                                                      │╰────────────────────────────────────────────╯
 │                                                                      │╭───────────────────NiuNiu───────────────────╮
 │                                                                      ││   --------------------------------------   │
 │                                                                      ││ /     Only two things are infinite,      \ │
 │                                                                      ││ \   the universe and human stupidity.    / │
 │                                                                      ││   --------------------------------------   │
 │                                                                      ││              ^__^     O   ^__^             │
 │                                                                      ││      _______/(oo)      o  (oo)\_______     │
 │                                                                      ││  /\/(       /(__)         (__)\       )\/\ │
 │                                                                      ││     ||w----||                 ||----w||    │
 │                                                                      ││     ||     ||                 ||     ||    │
 │                                                                      ││ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ │
 ╰──────────────────────────────────────────────────────────────────────╯╰────────────────────────────────────────────╯

使用方法

  • 使用默认值配置
var clientSettings = MongoClientSettings.FromUrl(mongoUrl);
clientSettings.ClusterConfigurator = cb => cb.Subscribe(new ActivityEventSubscriber());
var mongoClient = new MongoClient(clientSettings);
  • 使用集合名称进行过滤
var clientSettings = MongoClientSettings.FromUrl(mongoUrl);
// 定义需要输出的集合
HashSet<string> CommandsWithCollectionName = new()
{
    "mongo.test"
};
var options = new InstrumentationOptions()
{
    Enable = true,
    ShouldStartCollection = coll => CommandsWithCollectionName.Contains(coll)
};
clientSettings.ClusterConfigurator = cb => cb.Subscribe(new ActivityEventSubscriber(options));
var mongoClient = new MongoClient(clientSettings);
Seilog 配置例子
// 添加Serilog配置
builder.Host.UseSerilog((hbc, lc) =>
{
    const LogEventLevel logLevel = LogEventLevel.Information;
    lc.ReadFrom.Configuration(hbc.Configuration)
          .MinimumLevel.Override("Microsoft", logLevel)
          .MinimumLevel.Override("System", logLevel)
          .Enrich.FromLogContext()
          .WriteTo.Async(wt =>
          {
              wt.Debug();
              // 输出到 Spectre.Console
              wt.SpectreConsole();
          });
});

同时参考MongoDB.Driver.Core.Extensions.DiagnosticSources

Product Compatible and additional computed target framework versions.
.NET net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 is compatible. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
3.24.1003.33 36 10/2/2024
3.24.1002.162 33 10/2/2024
3.24.929.143 34 9/29/2024
3.24.929.141 40 9/29/2024
3.24.929.131 35 9/29/2024
3.24.929.122 39 9/29/2024
3.24.926.184 32 9/26/2024
3.24.926.182 41 9/26/2024
3.24.926.175 41 9/26/2024
3.24.924.160 36 9/24/2024
3.24.924.133 43 9/24/2024
3.24.924.124 34 9/24/2024
3.24.924.10 45 9/23/2024
3.24.924.1 40 9/23/2024
3.24.923.234 36 9/23/2024
3.24.923.232 38 9/23/2024
3.24.923.155 38 9/23/2024
3.24.919.92 49 9/19/2024
3.24.914.125 55 9/14/2024
3.24.914.115 41 9/14/2024
3.24.914.111 39 9/14/2024
3.24.911.95 46 9/11/2024
3.24.908.215 32 9/8/2024
3.24.904.200 44 9/4/2024
3.24.828.163 53 8/28/2024
3.24.820.173 54 8/20/2024
3.24.814.92 65 8/14/2024
3.24.812.115 61 8/12/2024
3.24.802.100 34 8/2/2024
3.24.801.162 45 8/1/2024
3.24.801.160 38 8/1/2024
3.24.801.155 41 8/1/2024
3.24.730.164 32 7/30/2024
3.24.730.91 30 7/30/2024
3.24.724.91 36 7/24/2024
3.24.718.105 51 7/18/2024
3.24.716.95 44 7/16/2024
3.24.712.94 42 7/12/2024
3.24.710.14 46 7/9/2024
3.24.709.105 45 7/9/2024
3.24.704.94 50 7/4/2024
3.24.701.90 54 7/1/2024
3.24.628.114 56 6/28/2024
3.24.627.145 45 6/27/2024
3.24.620.160 53 6/20/2024
3.24.613.115 50 6/13/2024
3.24.612.95 51 6/12/2024
3.24.528.90 50 5/28/2024
3.24.522.84 59 5/22/2024
3.24.512.213 57 5/12/2024
3.24.508.112 58 5/8/2024
2.2024.428.71 54 4/28/2024
2.2024.427.1128 102 4/27/2024
2.2.72 131 4/14/2024
2.2.71 53 4/12/2024
2.2.8 92 4/26/2024
2.2.6 54 4/10/2024
2.2.5 71 3/26/2024
2.2.4 70 3/25/2024
2.2.3 71 3/24/2024
2.2.2 73 3/21/2024
2.2.1 67 3/20/2024
2.2.0 73 3/13/2024
2.1.9 71 2/21/2024
2.1.8 79 2/18/2024
2.1.7 70 2/16/2024
2.1.6 71 2/14/2024
2.1.5 71 2/14/2024
2.1.4 69 2/9/2024
2.1.3 71 2/8/2024
2.1.2 70 2/5/2024
2.1.1.2 135 12/26/2023
2.1.1.1 81 12/26/2023
2.1.1 83 12/25/2023
2.1.0 94 12/17/2023
2.0.11 90 12/6/2023
2.0.1 91 11/15/2023
2.0.0 76 11/14/2023
1.9.1 96 11/1/2023
1.9.0 86 10/19/2023
1.9.0-preview2 78 10/12/2023
1.9.0-preview1 66 10/12/2023
1.8.9 94 10/11/2023
1.8.8 94 10/11/2023
1.8.7-rc2 76 9/21/2023
1.8.7-rc1 77 9/12/2023
1.8.6 114 8/31/2023
1.8.5 80 8/25/2023
1.8.4 86 8/24/2023
1.8.3 98 8/23/2023
1.8.2 155 8/22/2023
1.8.1 88 8/18/2023
1.8.0 580 8/15/2023
1.7.9 567 8/11/2023
1.7.8 534 8/11/2023
1.7.7 566 8/10/2023
1.7.6 617 8/9/2023
1.7.5 523 8/9/2023
1.7.4 639 8/3/2023
1.7.3 592 8/1/2023
1.7.2 631 7/31/2023
1.7.1 599 7/27/2023
1.7.0 604 7/25/2023
1.6.9 611 7/25/2023
1.6.8 624 7/24/2023
1.6.7 652 7/20/2023
1.6.6 661 7/19/2023
1.6.5 532 7/19/2023
1.6.4 618 7/17/2023
1.6.3 590 7/17/2023
1.6.2 643 7/12/2023
1.6.1 658 6/30/2023
1.6.0 620 6/26/2023
1.5.9 653 6/22/2023
1.5.8 625 6/15/2023
1.5.7.1 599 6/14/2023
1.5.7 619 6/14/2023
1.5.6.2 646 6/7/2023
1.5.6.1 620 6/7/2023
1.5.6 674 6/7/2023
1.5.5.2 588 5/26/2023
1.5.5.1 634 5/26/2023
1.5.5 661 5/26/2023
1.5.4.4 685 5/25/2023
1.5.4.3 644 5/23/2023
1.5.4.2 748 5/17/2023
1.5.4.1 658 5/16/2023
1.5.4 707 5/11/2023
1.5.3 652 5/11/2023
1.5.2 651 5/10/2023
1.5.1 620 5/10/2023
1.5.0 695 5/6/2023
1.4.0 690 5/5/2023
1.3.9 714 4/23/2023
1.3.8.6 703 4/23/2023
1.3.8.5 603 4/21/2023
1.3.8.1 727 4/12/2023
1.3.8 717 4/11/2023
1.3.7 689 4/9/2023
1.3.6.3 778 4/1/2023
1.3.6.2 695 3/31/2023
1.3.6.1 737 3/31/2023
1.3.6 720 3/31/2023
1.3.5 702 3/30/2023
1.3.4.1 792 3/29/2023
1.3.4 661 3/28/2023
1.3.3 637 3/28/2023
1.3.2 770 3/26/2023
1.3.1 843 3/22/2023
1.3.0 741 3/21/2023
1.2.0 664 3/21/2023
1.1.0 718 3/17/2023
1.0.9 685 3/15/2023
1.0.8 687 3/15/2023
1.0.7 685 3/15/2023
1.0.6 728 3/13/2023
1.0.5 773 3/13/2023
1.0.4 723 3/13/2023
1.0.2 781 2/26/2023
1.0.1 752 2/23/2023
1.0.0 727 2/20/2023