EasilyNET.Mongo.ConsoleDebug 2.2.3

There is a newer version of this package available.
See the version list below for details.
dotnet add package EasilyNET.Mongo.ConsoleDebug --version 2.2.3                
NuGet\Install-Package EasilyNET.Mongo.ConsoleDebug -Version 2.2.3                
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="2.2.3" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add EasilyNET.Mongo.ConsoleDebug --version 2.2.3                
#r "nuget: EasilyNET.Mongo.ConsoleDebug, 2.2.3"                
#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=2.2.3

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

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.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed. 
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
4.25.319.113 106 3/19/2025
4.25.312.103 120 3/12/2025
4.25.227.135 67 2/27/2025
4.25.221.115 58 2/21/2025
4.25.212.95 67 2/12/2025
4.25.211.140 61 2/11/2025
4.25.124.223 49 1/24/2025
4.25.116.110 52 1/16/2025
4.25.115.121 21 1/15/2025
4.25.114.172 41 1/14/2025
4.25.109.111 44 1/9/2025
4.25.108.182 48 1/8/2025
4.25.108.160 49 1/8/2025
4.25.1.1 76 1/1/2025
3.24.1224.141 60 12/24/2024
3.24.1216.116 73 12/16/2024
3.24.1206.100 64 12/6/2024
3.24.1205.171 67 12/5/2024
3.24.1202.150 69 12/2/2024
3.24.1126.231 63 11/26/2024
3.24.1126.172 62 11/26/2024
3.24.1126.114 70 11/26/2024
3.24.1126.104 65 11/26/2024
3.24.1125.181 48 11/25/2024
3.24.1125.104 64 11/25/2024
3.24.1121.183 57 11/21/2024
3.24.1120.183 61 11/20/2024
3.24.1119.31 60 11/18/2024
3.24.1115.143 49 11/15/2024
3.24.1113.100 66 11/13/2024
3.24.1112.125 66 11/12/2024
3.24.1107.140 59 11/7/2024
3.24.1107.54 59 11/7/2024
3.24.1107.34 59 11/7/2024
3.24.1105.111 61 11/5/2024
3.24.1103.31 70 11/2/2024
3.24.1103 68 11/2/2024
3.24.1031.135 57 10/31/2024
3.24.1031.112 60 10/31/2024
3.24.1031.104 61 10/31/2024
3.24.1029.142 67 10/29/2024
3.24.1025.30 62 10/24/2024
3.24.1022.142 50 10/22/2024
3.24.1018.204 116 10/18/2024
3.24.1018.175 108 10/18/2024
3.24.1018.166 107 10/18/2024
3.24.1018.93 116 10/18/2024
3.24.1017.42 63 10/16/2024
3.24.1016.161 64 10/16/2024
3.24.1015.231 64 10/15/2024
3.24.1015.14 64 10/14/2024
3.24.1012.114 65 10/12/2024
3.24.1009.115 66 10/9/2024
3.24.1008.160 60 10/8/2024
3.24.1008.133 67 10/8/2024
3.24.1007.185 63 10/7/2024
3.24.1003.33 70 10/2/2024
3.24.1002.162 65 10/2/2024
3.24.929.143 63 9/29/2024
3.24.929.141 66 9/29/2024
3.24.929.131 61 9/29/2024
3.24.929.122 69 9/29/2024
3.24.926.184 65 9/26/2024
3.24.926.182 66 9/26/2024
3.24.926.175 67 9/26/2024
3.24.924.160 62 9/24/2024
3.24.924.133 70 9/24/2024
3.24.924.124 60 9/24/2024
3.24.924.10 69 9/23/2024
3.24.924.1 64 9/23/2024
3.24.923.234 62 9/23/2024
3.24.923.232 60 9/23/2024
3.24.923.155 68 9/23/2024
3.24.919.92 76 9/19/2024
3.24.914.125 80 9/14/2024
3.24.914.115 67 9/14/2024
3.24.914.111 64 9/14/2024
3.24.911.95 68 9/11/2024
3.24.908.215 55 9/8/2024
3.24.904.200 64 9/4/2024
3.24.828.163 70 8/28/2024
3.24.820.173 78 8/20/2024
3.24.814.92 81 8/14/2024
3.24.812.115 79 8/12/2024
3.24.802.100 53 8/2/2024
3.24.801.162 63 8/1/2024
3.24.801.160 58 8/1/2024
3.24.801.155 60 8/1/2024
3.24.730.164 55 7/30/2024
3.24.730.91 53 7/30/2024
3.24.724.91 57 7/24/2024
3.24.718.105 73 7/18/2024
3.24.716.95 77 7/16/2024
3.24.712.94 62 7/12/2024
3.24.710.14 64 7/9/2024
3.24.709.105 64 7/9/2024
3.24.704.94 68 7/4/2024
3.24.701.90 74 7/1/2024
3.24.628.114 74 6/28/2024
3.24.627.145 64 6/27/2024
3.24.620.160 74 6/20/2024
3.24.613.115 68 6/13/2024
3.24.612.95 68 6/12/2024
3.24.528.90 66 5/28/2024
3.24.522.84 78 5/22/2024
3.24.512.213 72 5/12/2024
3.24.508.112 77 5/8/2024
2.2024.428.71 69 4/28/2024
2.2024.427.1128 116 4/27/2024
2.2.72 146 4/14/2024
2.2.71 69 4/12/2024
2.2.8 109 4/26/2024
2.2.6 70 4/10/2024
2.2.5 83 3/26/2024
2.2.4 82 3/25/2024
2.2.3 85 3/24/2024
2.2.2 87 3/21/2024
2.2.1 82 3/20/2024
2.2.0 88 3/13/2024
2.1.9 90 2/21/2024
2.1.8 95 2/18/2024
2.1.7 85 2/16/2024
2.1.6 92 2/14/2024
2.1.5 93 2/14/2024
2.1.4 91 2/9/2024
2.1.3 89 2/8/2024
2.1.2 89 2/5/2024
2.1.1.2 147 12/26/2023
2.1.1.1 92 12/26/2023
2.1.1 94 12/25/2023
2.1.0 109 12/17/2023
2.0.11 110 12/6/2023
2.0.1 107 11/15/2023
2.0.0 88 11/14/2023
1.9.1 111 11/1/2023
1.9.0 97 10/19/2023
1.9.0-preview2 88 10/12/2023
1.9.0-preview1 76 10/12/2023
1.8.9 105 10/11/2023
1.8.8 104 10/11/2023
1.8.7-rc2 84 9/21/2023
1.8.7-rc1 86 9/12/2023
1.8.6 127 8/31/2023
1.8.5 102 8/25/2023
1.8.4 102 8/24/2023
1.8.3 109 8/23/2023
1.8.2 168 8/22/2023
1.8.1 98 8/18/2023
1.8.0 594 8/15/2023
1.7.9 580 8/11/2023
1.7.8 552 8/11/2023
1.7.7 580 8/10/2023
1.7.6 627 8/9/2023
1.7.5 536 8/9/2023
1.7.4 658 8/3/2023
1.7.3 605 8/1/2023
1.7.2 644 7/31/2023
1.7.1 612 7/27/2023
1.7.0 617 7/25/2023
1.6.9 624 7/25/2023
1.6.8 636 7/24/2023
1.6.7 664 7/20/2023
1.6.6 679 7/19/2023
1.6.5 553 7/19/2023
1.6.4 636 7/17/2023
1.6.3 602 7/17/2023
1.6.2 664 7/12/2023
1.6.1 685 6/30/2023
1.6.0 634 6/26/2023
1.5.9 664 6/22/2023
1.5.8 638 6/15/2023
1.5.7.1 614 6/14/2023
1.5.7 635 6/14/2023
1.5.6.2 661 6/7/2023
1.5.6.1 635 6/7/2023
1.5.6 689 6/7/2023
1.5.5.2 602 5/26/2023
1.5.5.1 649 5/26/2023
1.5.5 678 5/26/2023
1.5.4.4 701 5/25/2023
1.5.4.3 671 5/23/2023
1.5.4.2 765 5/17/2023
1.5.4.1 678 5/16/2023
1.5.4 725 5/11/2023
1.5.3 668 5/11/2023
1.5.2 669 5/10/2023
1.5.1 636 5/10/2023
1.5.0 717 5/6/2023
1.4.0 712 5/5/2023
1.3.9 729 4/23/2023
1.3.8.6 720 4/23/2023
1.3.8.5 627 4/21/2023
1.3.8.1 744 4/12/2023
1.3.8 735 4/11/2023
1.3.7 707 4/9/2023
1.3.6.3 794 4/1/2023
1.3.6.2 711 3/31/2023
1.3.6.1 753 3/31/2023
1.3.6 738 3/31/2023
1.3.5 720 3/30/2023
1.3.4.1 809 3/29/2023
1.3.4 677 3/28/2023
1.3.3 659 3/28/2023
1.3.2 787 3/26/2023
1.3.1 859 3/22/2023
1.3.0 756 3/21/2023
1.2.0 679 3/21/2023
1.1.0 739 3/17/2023
1.0.9 700 3/15/2023
1.0.8 703 3/15/2023
1.0.7 701 3/15/2023
1.0.6 746 3/13/2023
1.0.5 788 3/13/2023
1.0.4 739 3/13/2023
1.0.2 798 2/26/2023
1.0.1 771 2/23/2023
1.0.0 744 2/20/2023