From 7085fe5f6ecbb7fa844c26e2142b441b651b9ab3 Mon Sep 17 00:00:00 2001 From: Jaben Cargman Date: Sat, 17 Feb 2024 19:12:33 -0500 Subject: [PATCH 01/10] Update deploy.yml Fixed package push --- .github/workflows/deploy.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index 878602e..ce5c2ee 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -46,4 +46,5 @@ jobs: - name: Publish if: github.event_name != 'pull_request' && (github.ref_name == 'master') run: | + dotnet nuget push **/*.nupkg --source 'https://api.nuget.org/v3/index.json' -k ${{ secrets.NUGETKEY }} --skip-duplicate dotnet nuget push **/*.snupkg --source 'https://api.nuget.org/v3/index.json' -k ${{ secrets.NUGETKEY }} --skip-duplicate From d3de244c5b6628af9bb160220db9460978695446 Mon Sep 17 00:00:00 2001 From: Jaben Date: Sun, 18 Feb 2024 11:48:17 -0500 Subject: [PATCH 02/10] Added license expression. --- src/Serilog.Sinks.MongoDB/Serilog.Sinks.MongoDB.csproj | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Serilog.Sinks.MongoDB/Serilog.Sinks.MongoDB.csproj b/src/Serilog.Sinks.MongoDB/Serilog.Sinks.MongoDB.csproj index abb446f..7b3db0a 100644 --- a/src/Serilog.Sinks.MongoDB/Serilog.Sinks.MongoDB.csproj +++ b/src/Serilog.Sinks.MongoDB/Serilog.Sinks.MongoDB.csproj @@ -13,6 +13,7 @@ Kiran Makkapati, Jaben Cargman, Serilog Contributors Copyright © Serilog Contributors 2014-2022 The MongoDB sink for Serilog + Apache-2.0 http://serilog.net/images/serilog-sink-nuget.png Serilog.Sinks.MongoDB http://serilog.net From 2881b6af49f58069756131aebd0945ea74f2c62f Mon Sep 17 00:00:00 2001 From: Jaben Date: Sun, 18 Feb 2024 11:50:49 -0500 Subject: [PATCH 03/10] Updating to latest github action versions -- other fixes. --- .github/workflows/deploy.yml | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index ce5c2ee..31102a1 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -12,23 +12,23 @@ jobs: steps: - name: Checkout - uses: actions/checkout@v2 + uses: actions/checkout@v4 with: fetch-depth: 0 - name: Setup Dotnet - uses: actions/setup-dotnet@v1 + uses: actions/setup-dotnet@v4 with: dotnet-version: ${{ matrix.dotnet-version }} - name: Install GitVersion - uses: gittools/actions/gitversion/setup@v0.9.7 + uses: gittools/actions/gitversion/setup@v0.11.0 with: versionSpec: '5.x' - name: GitVersion id: gitversion - uses: gittools/actions/gitversion/execute@v0.9.7 + uses: gittools/actions/gitversion/execute@v0.11.0 with: useConfigFile: true @@ -41,10 +41,10 @@ jobs: run: dotnet test - name: Pack - run: dotnet pack -c Release -p:PackageVersion=${{ steps.gitversion.outputs.nuGetVersion }} -p:IncludeSymbols=true -p:SymbolPackageFormat=snupkg + run: dotnet build -c Release -p:PackageVersion=${{ steps.gitversion.outputs.nuGetVersion }} -p:IncludeSymbols=true -p:SymbolPackageFormat=snupkg - name: Publish if: github.event_name != 'pull_request' && (github.ref_name == 'master') run: | - dotnet nuget push **/*.nupkg --source 'https://api.nuget.org/v3/index.json' -k ${{ secrets.NUGETKEY }} --skip-duplicate - dotnet nuget push **/*.snupkg --source 'https://api.nuget.org/v3/index.json' -k ${{ secrets.NUGETKEY }} --skip-duplicate + dotnet nuget push **/bin/Release/*.nupkg --source 'https://api.nuget.org/v3/index.json' -k ${{ secrets.NUGETKEY }} --skip-duplicate + dotnet nuget push **/bin/Release/*.snupkg --source 'https://api.nuget.org/v3/index.json' -k ${{ secrets.NUGETKEY }} --skip-duplicate From d824af689ce1a112b2a9e0195a92882fdc557d6d Mon Sep 17 00:00:00 2001 From: Jaben Cargman Date: Sun, 18 Feb 2024 11:55:09 -0500 Subject: [PATCH 04/10] Added Badges! --- README.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 06fd15c..2334cfb 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,8 @@ # ![mongo icon](https://raw.githubusercontent.com/ChangemakerStudios/serilog-sinks-mongodb/dev/assets/mongo-icon.png) Serilog.Sinks.MongoDB -![Build status](https://github.com/ChangemakerStudios/serilog-sinks-mongodb/actions/workflows/deploy.yml/badge.svg) +[![NuGet version](https://badge.fury.io/nu/Serilog.Sinks.MongoDB.svg)](https://badge.fury.io/nu/Serilog.Sinks.MongoDB) +[![Downloads](https://img.shields.io/nuget/dt/Serilog.Sinks.MongoDB.svg?logo=nuget&color=purple)](https://www.nuget.org/packages/Serilog.Sinks.MongoDB) +[![Build status](https://github.com/ChangemakerStudios/serilog-sinks-mongodb/actions/workflows/deploy.yml/badge.svg)](https://github.com/ChangemakerStudios/serilog-sinks-mongodb/actions) A Serilog sink that writes events as documents to [MongoDB](http://mongodb.org). From 998498e425483decb9d9a1c4bcf7b5392f5542ee Mon Sep 17 00:00:00 2001 From: Jaben Date: Sun, 18 Feb 2024 11:59:05 -0500 Subject: [PATCH 05/10] Killing warnings. --- .../Serilog.Sinks.MongoDB.csproj | 14 +++++++++++--- .../serilog-sink-nuget.png | Bin 0 -> 20852 bytes 2 files changed, 11 insertions(+), 3 deletions(-) create mode 100644 src/Serilog.Sinks.MongoDB/serilog-sink-nuget.png diff --git a/src/Serilog.Sinks.MongoDB/Serilog.Sinks.MongoDB.csproj b/src/Serilog.Sinks.MongoDB/Serilog.Sinks.MongoDB.csproj index 7b3db0a..ef51921 100644 --- a/src/Serilog.Sinks.MongoDB/Serilog.Sinks.MongoDB.csproj +++ b/src/Serilog.Sinks.MongoDB/Serilog.Sinks.MongoDB.csproj @@ -14,11 +14,9 @@ Copyright © Serilog Contributors 2014-2022 The MongoDB sink for Serilog Apache-2.0 - http://serilog.net/images/serilog-sink-nuget.png Serilog.Sinks.MongoDB http://serilog.net - https://github.com/ChangemakerStudios/serilog-sinks-mongodb - git + serilog-sink-nuget.png serilog, mongodb README.md @@ -27,12 +25,22 @@ + https://github.com/ChangemakerStudios/serilog-sinks-mongodb + git true true true snupkg + + true + + + + + + diff --git a/src/Serilog.Sinks.MongoDB/serilog-sink-nuget.png b/src/Serilog.Sinks.MongoDB/serilog-sink-nuget.png new file mode 100644 index 0000000000000000000000000000000000000000..a77d65c42658e49e801aebde26b767d3916e6971 GIT binary patch literal 20852 zcmb4rbyQVbwD%#UyQEW4T0%rRBqRhW=@yWbM!G{95hMgex}~L4K?M;6=}=HW_Uc!k3`d+#;ZoWEMe+}BVd#G}PSp-_Y>$_m;j6dL?58VUy+{xE)0Vhev@ zy348P;J}wZj&(Hr9oJR)p*sr2CXM`u7WP5g0KR$EL(#zFfs3t&x5X11l()AxpS|;A zcPk558$OpOkFvHTXi+F;l!}6^j!*VRj<2!W<3I1&TC6t|9;(_k=-_eO zQ)tAAD6Ggg=^NB&B(AfG*-%l5;CVBlp%ATVpR>RexWX;+^<%rYt?JRq$eN)0_F3DA zlKV*e(Lbp*PZ}?)!8%#_ukXKnos3%Vi7>AUmM3AynVw!GDk$j3&z~_K^V4}4DD~HUmVG#48d=x&e7`%2 zUd+{DX}*1{DCO;hyz>_edmF4MmDIkQN40E9Nf}AZ=`D}Lh)}}ucv-bpg7cp>c-)m1 znnT_``W$WJ?EK%am`hurS2#KL-Sl=)#XH=X=16bxl|`N2#{q58VTKd44T(gM{L! zQDL9cKYuKf-`!zn?>lnmB_LM<5WRO3R&glXXJmR<$5#?BDJN1=VW z<(wC5!r`p1+&y}4^fd;GP@PS&{$`1=uYr9C48Fv*XaEJeiR9pB^*!lfBfK& zE^0LW>)l70pW&J!i@wPCisWI+qkB1R<}JuEUA{lZurCsRqUuiamjk<4DpxMhH!xoC zCePK4FSB7m))#1~zMq2@Zr?1+OfXP=>-}LTMzccgF0rAp==mQNyF5N7a)4lsV5jS&Z zV>#wfdow72I+Ob0X7=)srSXY>#EnTiJG*9?@7yvjE%Osn3m1NLMy4)k9L}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z&ld9CSVIW_1HxJjZ|Bz;gpM1YFt-8G$eJMM59%xefsmM&_Z>Z4 z$9ARPgd|lSL}*wvw=!aU0&hdj3T|pcJ?!^vIB_J@r6&C6Ht;5(XA!CBDpys*&a>#{ z3+0#3Ku)ck&8|^sSp*}k2j~s1LL?Lhq@}%}We$v|OGJ3?pKxewn)-Y>WjOg9oYlKVV|A#D zqR+A;8ZYYVBIB_`$>On3pE}wr$5NBx<54fCLi`&KGUFxyS{4pAg&zde-tj+-PC9mc zUY|5`S!{-?dY{zuD|6v?O6wXfzt^5E3lv75#JO6NtDQ$iN1=Vrn+Ta18+$ar)hZNn zn0~QFv$|VeGHCaThyl+PYS7J7>n$KDAu8i&CGYQ<%kcK`Df;8AHCbc$``h=VMdb(; zlS%*rn=FPXkX}ur)^8H(D>a$~Wf?hE3jCEp*#3Ionv)Cbu)ps=7+(dSI501&!gpqN zc6-lMr%ZOHEE4lV9e8sXroq{|A6!}#g&al_5aSE~2RkkK AFaQ7m literal 0 HcmV?d00001 From 19dd834bb9b148e8b09e703ecc4bf1adca343f1a Mon Sep 17 00:00:00 2001 From: Jaben Date: Sun, 18 Feb 2024 12:00:08 -0500 Subject: [PATCH 06/10] Tired of this warning. --- src/Serilog.Sinks.MongoDB/Sinks/MongoDB/MongoDBJsonFormatter.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Serilog.Sinks.MongoDB/Sinks/MongoDB/MongoDBJsonFormatter.cs b/src/Serilog.Sinks.MongoDB/Sinks/MongoDB/MongoDBJsonFormatter.cs index 619e86a..b09a4b6 100644 --- a/src/Serilog.Sinks.MongoDB/Sinks/MongoDB/MongoDBJsonFormatter.cs +++ b/src/Serilog.Sinks.MongoDB/Sinks/MongoDB/MongoDBJsonFormatter.cs @@ -84,7 +84,7 @@ protected override void WriteJsonProperty( } else { - base.WriteJsonProperty(name, value, ref precedingDelimiter, output); + base.WriteJsonProperty(name, value!, ref precedingDelimiter, output); } } From bb6e973c1be9667618778eb8e47da180bdfeaea2 Mon Sep 17 00:00:00 2001 From: Jaben Date: Sun, 18 Feb 2024 12:22:03 -0500 Subject: [PATCH 07/10] Feature for Issue #82 Bson sink supports excluding the "MessageTemplate" as it can be redundant/unnecessary since the RenderedMessage exists. --- .../Sinks/MongoDB/LogEntry.cs | 31 ++++++++++++------- .../Sinks/MongoDB/MongoDBSink.cs | 2 +- .../Sinks/MongoDB/MongoDBSinkBase.cs | 4 ++- .../Sinks/MongoDB/MongoDBSinkConfiguration.cs | 18 +++++++++++ 4 files changed, 41 insertions(+), 14 deletions(-) diff --git a/src/Serilog.Sinks.MongoDB/Sinks/MongoDB/LogEntry.cs b/src/Serilog.Sinks.MongoDB/Sinks/MongoDB/LogEntry.cs index e78458d..350251c 100644 --- a/src/Serilog.Sinks.MongoDB/Sinks/MongoDB/LogEntry.cs +++ b/src/Serilog.Sinks.MongoDB/Sinks/MongoDB/LogEntry.cs @@ -33,6 +33,7 @@ public class LogEntry public DateTime UtcTimeStamp { get; set; } + [BsonIgnoreIfNull] public MessageTemplate? MessageTemplate { get; set; } public string? RenderedMessage { get; set; } @@ -41,21 +42,27 @@ public class LogEntry public BsonDocument? Exception { get; set; } - public static LogEntry MapFrom(LogEvent logEvent) + public static LogEntry MapFrom(LogEvent logEvent, bool includeMessageTemplate) { if (logEvent == null) throw new ArgumentNullException(nameof(logEvent)); - return new LogEntry + var logEntry = new LogEntry + { + RenderedMessage = logEvent.RenderMessage(), + Level = logEvent.Level, + UtcTimeStamp = logEvent.Timestamp.ToUniversalTime().UtcDateTime, + Exception = logEvent.Exception?.ToBsonDocument().SanitizeDocumentRecursive(), + Properties = BsonDocument.Create( + logEvent.Properties.ToDictionary( + s => s.Key.SanitizedElementName(), + s => s.Value.ToBsonValue())) + }; + + if (includeMessageTemplate) { - MessageTemplate = logEvent.MessageTemplate, - RenderedMessage = logEvent.RenderMessage(), - Level = logEvent.Level, - UtcTimeStamp = logEvent.Timestamp.ToUniversalTime().UtcDateTime, - Exception = logEvent.Exception?.ToBsonDocument().SanitizeDocumentRecursive(), - Properties = BsonDocument.Create( - logEvent.Properties.ToDictionary( - s => s.Key.SanitizedElementName(), - s => s.Value.ToBsonValue())) - }; + logEntry.MessageTemplate = logEvent.MessageTemplate; + } + + return logEntry; } } \ No newline at end of file diff --git a/src/Serilog.Sinks.MongoDB/Sinks/MongoDB/MongoDBSink.cs b/src/Serilog.Sinks.MongoDB/Sinks/MongoDB/MongoDBSink.cs index 91d4d70..41a4a7b 100644 --- a/src/Serilog.Sinks.MongoDB/Sinks/MongoDB/MongoDBSink.cs +++ b/src/Serilog.Sinks.MongoDB/Sinks/MongoDB/MongoDBSink.cs @@ -46,6 +46,6 @@ public MongoDBSink(MongoDBSinkConfiguration configuration) public override Task EmitBatchAsync(IEnumerable events) { - return this.InsertMany(events.Select(LogEntry.MapFrom)); + return this.InsertMany(events.Select(@event => LogEntry.MapFrom(@event, this.IncludeMessageTemplate))); } } \ No newline at end of file diff --git a/src/Serilog.Sinks.MongoDB/Sinks/MongoDB/MongoDBSinkBase.cs b/src/Serilog.Sinks.MongoDB/Sinks/MongoDB/MongoDBSinkBase.cs index a7fe84f..fee2678 100644 --- a/src/Serilog.Sinks.MongoDB/Sinks/MongoDB/MongoDBSinkBase.cs +++ b/src/Serilog.Sinks.MongoDB/Sinks/MongoDB/MongoDBSinkBase.cs @@ -39,7 +39,7 @@ public abstract class MongoDBSinkBase : IBatchedLogEventSink /// protected MongoDBSinkBase(MongoDBSinkConfiguration configuration) { - if (configuration == null) throw new ArgumentNullException(nameof(configuration)); + if (configuration! == null) throw new ArgumentNullException(nameof(configuration)); this._configuration = configuration; @@ -51,6 +51,8 @@ protected MongoDBSinkBase(MongoDBSinkConfiguration configuration) LazyThreadSafetyMode.ExecutionAndPublication); } + protected bool IncludeMessageTemplate => !this._configuration.ExcludeMessageTemplate; + protected string CollectionName => this._configuration.CollectionName; protected RollingInterval RollingInterval => this._configuration.RollingInterval; diff --git a/src/Serilog.Sinks.MongoDB/Sinks/MongoDB/MongoDBSinkConfiguration.cs b/src/Serilog.Sinks.MongoDB/Sinks/MongoDB/MongoDBSinkConfiguration.cs index b5b5b6a..22f1b82 100644 --- a/src/Serilog.Sinks.MongoDB/Sinks/MongoDB/MongoDBSinkConfiguration.cs +++ b/src/Serilog.Sinks.MongoDB/Sinks/MongoDB/MongoDBSinkConfiguration.cs @@ -38,6 +38,8 @@ public class MongoDBSinkConfiguration public bool Legacy { get; internal set; } + public bool ExcludeMessageTemplate { get; internal set; } + public InsertManyOptions? InsertManyOptions { get; internal set; } public RollingInterval RollingInterval { get; private set; } = RollingInterval.Infinite; @@ -58,6 +60,11 @@ public void Validate() throw new ArgumentNullException( nameof(this.ExpireTTL), "Expiration TTL is only supported on the MongoDBBson Sink"); + + if (this.ExcludeMessageTemplate && this.Legacy) + throw new ArgumentNullException( + nameof(this.ExcludeMessageTemplate), + "Exclude Message Template is only supported on the MongoDBBson Sink"); } /// @@ -88,6 +95,17 @@ public void SetExpireTTL(TimeSpan? timeToLive) this.ExpireTTL = timeToLive; } + /// + /// Sets if the log should include the "MessageTemplate" field, + /// as the RenderedMessage field is already included the "MessageTemplate" + /// may be unnecessary/redundant. + /// + /// + public void SetExcludeMessageTemplate(bool excludeMessageTemplate) + { + this.ExcludeMessageTemplate = excludeMessageTemplate; + } + /// /// Allows configuring "InsertManyOptions" in MongoDb. /// From bfa4614d8a08cd6db0844516c903cdc071ac03ba Mon Sep 17 00:00:00 2001 From: memoyu Date: Tue, 13 Aug 2024 12:15:41 +0800 Subject: [PATCH 08/10] upgrade MongoDB.Driver to v2.28.0 (#85) Thanks for the PR --- src/Serilog.Sinks.MongoDB/Serilog.Sinks.MongoDB.csproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Serilog.Sinks.MongoDB/Serilog.Sinks.MongoDB.csproj b/src/Serilog.Sinks.MongoDB/Serilog.Sinks.MongoDB.csproj index ef51921..f66cf50 100644 --- a/src/Serilog.Sinks.MongoDB/Serilog.Sinks.MongoDB.csproj +++ b/src/Serilog.Sinks.MongoDB/Serilog.Sinks.MongoDB.csproj @@ -53,7 +53,7 @@ - + From d6a5703ec02fafb70e43c8cfea76152b22a5e1b6 Mon Sep 17 00:00:00 2001 From: Fernando Mariano Pereira Date: Fri, 6 Sep 2024 23:15:52 -0300 Subject: [PATCH 09/10] Add trace context to LogEntry (#87) * upgrade Serilog from 2.12.0 to 3.1.1 * add TraceId and SpanId to LogEntry add tests to validate that trace data is saving --- .../Serilog.Sinks.MongoDB.csproj | 2 +- .../Sinks/MongoDB/LogEntry.cs | 7 ++ .../LoggerWithTraceIdTests.cs | 108 ++++++++++++++++++ 3 files changed, 116 insertions(+), 1 deletion(-) create mode 100644 test/Serilog.Sinks.MongoDB.Tests/LoggerWithTraceIdTests.cs diff --git a/src/Serilog.Sinks.MongoDB/Serilog.Sinks.MongoDB.csproj b/src/Serilog.Sinks.MongoDB/Serilog.Sinks.MongoDB.csproj index f66cf50..e15667a 100644 --- a/src/Serilog.Sinks.MongoDB/Serilog.Sinks.MongoDB.csproj +++ b/src/Serilog.Sinks.MongoDB/Serilog.Sinks.MongoDB.csproj @@ -50,7 +50,7 @@ - + diff --git a/src/Serilog.Sinks.MongoDB/Sinks/MongoDB/LogEntry.cs b/src/Serilog.Sinks.MongoDB/Sinks/MongoDB/LogEntry.cs index 350251c..b3a1339 100644 --- a/src/Serilog.Sinks.MongoDB/Sinks/MongoDB/LogEntry.cs +++ b/src/Serilog.Sinks.MongoDB/Sinks/MongoDB/LogEntry.cs @@ -13,6 +13,7 @@ // limitations under the License. using System; +using System.Diagnostics; using System.Linq; using MongoDB.Bson; @@ -41,6 +42,10 @@ public class LogEntry public BsonDocument? Properties { get; set; } public BsonDocument? Exception { get; set; } + [BsonIgnoreIfNull] + public string? TraceId { get; set; } + [BsonIgnoreIfNull] + public string? SpanId { get; set; } public static LogEntry MapFrom(LogEvent logEvent, bool includeMessageTemplate) { @@ -51,6 +56,8 @@ public static LogEntry MapFrom(LogEvent logEvent, bool includeMessageTemplate) RenderedMessage = logEvent.RenderMessage(), Level = logEvent.Level, UtcTimeStamp = logEvent.Timestamp.ToUniversalTime().UtcDateTime, + TraceId = logEvent.TraceId?.ToString(), + SpanId = logEvent.SpanId?.ToString(), Exception = logEvent.Exception?.ToBsonDocument().SanitizeDocumentRecursive(), Properties = BsonDocument.Create( logEvent.Properties.ToDictionary( diff --git a/test/Serilog.Sinks.MongoDB.Tests/LoggerWithTraceIdTests.cs b/test/Serilog.Sinks.MongoDB.Tests/LoggerWithTraceIdTests.cs new file mode 100644 index 0000000..ad65844 --- /dev/null +++ b/test/Serilog.Sinks.MongoDB.Tests/LoggerWithTraceIdTests.cs @@ -0,0 +1,108 @@ +using FluentAssertions; + +using Microsoft.Extensions.Configuration; + +using MongoDB.Driver; + +using Serilog.Helpers; + +namespace Serilog.Sinks.MongoDB.Tests; + +using System.Diagnostics; +using NUnit.Framework; + +[TestFixture] +public class LoggerWithTraceIdTests +{ + private const string MongoConnectionString = "mongodb://localhost:27017"; + + private const string MongoDatabaseName = "mongodb-sink"; + + private static (MongoClient, IMongoDatabase) GetDatabase() + { + var mongoClient = new MongoClient(MongoConnectionString); + return (mongoClient, mongoClient.GetDatabase(MongoDatabaseName)); + } + + [Test] + public void Log_Without_Activity_Should_Have_TraceId_And_SpanId_Null() + { + var configuration = new ConfigurationBuilder() + .AddJsonFile("serilog.json") + .Build(); + + var collectionName = RollingInterval.Month.GetCollectionName("test"); + + const string Message = "some message logged into mongodb without activity"; + + using (var logger = new LoggerConfiguration() + .ReadFrom.Configuration(configuration) + .CreateLogger()) + { + logger.Information(Message); + } + + var (mongoClient, mongoDatabase) = GetDatabase(); + var collectionExists = mongoDatabase.CollectionExists(collectionName); + + collectionExists.Should().BeTrue(); + + var mongoCollection = mongoDatabase.GetCollection(collectionName); + var document = mongoCollection.Find(x => x.RenderedMessage == Message).FirstOrDefault(); + + document.Should().NotBeNull(); + document.TraceId.Should().BeNull(); + document.SpanId.Should().BeNull(); + + mongoClient.DropDatabase(MongoDatabaseName); + } + + [Test] + public void Log_Within_Activity_Should_Have_TraceId_And_SpanId_Not_Null() + { + ActivityTraceId traceId; + ActivitySpanId spanId; + + var configuration = new ConfigurationBuilder() + .AddJsonFile("serilog.json") + .Build(); + + var collectionName = RollingInterval.Month.GetCollectionName("test"); + + const string Message = "some message logged into mongodb within an activity"; + + using (var logger = new LoggerConfiguration() + .ReadFrom.Configuration(configuration) + .CreateLogger()) + { + var activitySource = new ActivitySource("Serilog.Sinks.MongoDB.Tests"); + var activityListener = new ActivityListener + { + ShouldListenTo = s => true, + SampleUsingParentId = (ref ActivityCreationOptions activityOptions) => ActivitySamplingResult.AllData, + Sample = (ref ActivityCreationOptions activityOptions) => ActivitySamplingResult.AllData + }; + ActivitySource.AddActivityListener(activityListener); + using (var activity = activitySource.StartActivity("LogTest")) + { + traceId = activity.TraceId; + spanId = activity.SpanId; + logger.Information(Message); + } + } + + var (mongoClient, mongoDatabase) = GetDatabase(); + var collectionExists = mongoDatabase.CollectionExists(collectionName); + + collectionExists.Should().BeTrue(); + + var mongoCollection = mongoDatabase.GetCollection(collectionName); + var document = mongoCollection.Find(x => x.RenderedMessage == Message).FirstOrDefault(); + + document.Should().NotBeNull(); + document.TraceId.Should().Be(traceId.ToString()); + document.SpanId.Should().Be(spanId.ToString()); + + mongoClient.DropDatabase(MongoDatabaseName); + } +} \ No newline at end of file From 43f0881cd2f6b702ac29dfce933c6c64ece7e9dc Mon Sep 17 00:00:00 2001 From: Jaben Cargman Date: Thu, 19 Sep 2024 23:24:51 -0400 Subject: [PATCH 10/10] Readying release v6.0 --- README.md | 3 ++ .../Helpers/MongoDbDocumentHelpers.cs | 2 +- .../Helpers/MongoDbHelpers.cs | 2 +- .../Helpers/RollingIntervalHelper.cs | 2 +- .../Helpers/StringHelpers.cs | 2 +- .../LoggerConfigurationMongoDBExtensions.cs | 2 +- .../Serilog.Sinks.MongoDB.csproj | 4 +-- .../Sinks/MongoDB/LogEntry.cs | 2 +- .../Sinks/MongoDB/MongoDBJsonFormatter.cs | 2 +- .../Sinks/MongoDB/MongoDBSink.cs | 30 +++++++++++++++++-- .../Sinks/MongoDB/MongoDBSinkBase.cs | 2 +- .../Sinks/MongoDB/MongoDBSinkConfiguration.cs | 2 +- .../Sinks/MongoDB/MongoDBSinkDefaults.cs | 2 +- .../Sinks/MongoDB/MongoDBSinkLegacy.cs | 2 +- .../Sinks/MongoDB/RollingInterval.cs | 2 +- .../Serilog.Sinks.MongoDB.Tests.csproj | 8 ++--- 16 files changed, 49 insertions(+), 20 deletions(-) diff --git a/README.md b/README.md index 2334cfb..69a0ec9 100644 --- a/README.md +++ b/README.md @@ -9,6 +9,9 @@ A Serilog sink that writes events as documents to [MongoDB](http://mongodb.org). **Package** - [Serilog.Sinks.MongoDB](http://nuget.org/packages/serilog.sinks.mongodb) | **Platforms** - .NET 4.7.2, .NET Standard 2.0,, .NET Standard 2.1 +### New in v6.x +* Upgraded to MongoDb v2.28 -- fixing breaking changes. + ### New in v5.x * Output structured MongoDB Bson logs by switching to the .MongoDBBson() extensions. Existing the .MongoDB() extensions will continue to work converting logs to Json and then to Bson. * Rolling Log Collection Naming (Thanks to [Revazashvili](https://github.com/Revazashvili) for the PR!). MongoDBBson sink only. diff --git a/src/Serilog.Sinks.MongoDB/Helpers/MongoDbDocumentHelpers.cs b/src/Serilog.Sinks.MongoDB/Helpers/MongoDbDocumentHelpers.cs index ce63276..cb31eee 100644 --- a/src/Serilog.Sinks.MongoDB/Helpers/MongoDbDocumentHelpers.cs +++ b/src/Serilog.Sinks.MongoDB/Helpers/MongoDbDocumentHelpers.cs @@ -1,4 +1,4 @@ -// Copyright 2014-2022 Serilog Contributors +// Copyright 2014-2024 Serilog Contributors // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/src/Serilog.Sinks.MongoDB/Helpers/MongoDbHelpers.cs b/src/Serilog.Sinks.MongoDB/Helpers/MongoDbHelpers.cs index 67625a7..af2a360 100644 --- a/src/Serilog.Sinks.MongoDB/Helpers/MongoDbHelpers.cs +++ b/src/Serilog.Sinks.MongoDB/Helpers/MongoDbHelpers.cs @@ -1,4 +1,4 @@ -// Copyright 2014-2022 Serilog Contributors +// Copyright 2014-2024 Serilog Contributors // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/src/Serilog.Sinks.MongoDB/Helpers/RollingIntervalHelper.cs b/src/Serilog.Sinks.MongoDB/Helpers/RollingIntervalHelper.cs index f5ea6e8..5f70593 100644 --- a/src/Serilog.Sinks.MongoDB/Helpers/RollingIntervalHelper.cs +++ b/src/Serilog.Sinks.MongoDB/Helpers/RollingIntervalHelper.cs @@ -1,4 +1,4 @@ -// Copyright 2014-2022 Serilog Contributors +// Copyright 2014-2024 Serilog Contributors // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/src/Serilog.Sinks.MongoDB/Helpers/StringHelpers.cs b/src/Serilog.Sinks.MongoDB/Helpers/StringHelpers.cs index d00a4e5..6b1207c 100644 --- a/src/Serilog.Sinks.MongoDB/Helpers/StringHelpers.cs +++ b/src/Serilog.Sinks.MongoDB/Helpers/StringHelpers.cs @@ -1,4 +1,4 @@ -// Copyright 2014-2022 Serilog Contributors +// Copyright 2014-2024 Serilog Contributors // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/src/Serilog.Sinks.MongoDB/LoggerConfigurationMongoDBExtensions.cs b/src/Serilog.Sinks.MongoDB/LoggerConfigurationMongoDBExtensions.cs index 09d65d3..96bf3ef 100644 --- a/src/Serilog.Sinks.MongoDB/LoggerConfigurationMongoDBExtensions.cs +++ b/src/Serilog.Sinks.MongoDB/LoggerConfigurationMongoDBExtensions.cs @@ -1,4 +1,4 @@ -// Copyright 2014-2022 Serilog Contributors +// Copyright 2014-2024 Serilog Contributors // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/src/Serilog.Sinks.MongoDB/Serilog.Sinks.MongoDB.csproj b/src/Serilog.Sinks.MongoDB/Serilog.Sinks.MongoDB.csproj index e15667a..e21fc07 100644 --- a/src/Serilog.Sinks.MongoDB/Serilog.Sinks.MongoDB.csproj +++ b/src/Serilog.Sinks.MongoDB/Serilog.Sinks.MongoDB.csproj @@ -9,7 +9,7 @@ - 5.4.0 + 6.0.0 Kiran Makkapati, Jaben Cargman, Serilog Contributors Copyright © Serilog Contributors 2014-2022 The MongoDB sink for Serilog @@ -20,7 +20,7 @@ serilog, mongodb README.md - v5.4 - Upgraded to MongoDB.Driver to version 2.19 due to vulnerabilities. + v6.0 - Upgraded to MongoDB.Driver to version 2.28 due to incompatibilities. diff --git a/src/Serilog.Sinks.MongoDB/Sinks/MongoDB/LogEntry.cs b/src/Serilog.Sinks.MongoDB/Sinks/MongoDB/LogEntry.cs index b3a1339..72cea66 100644 --- a/src/Serilog.Sinks.MongoDB/Sinks/MongoDB/LogEntry.cs +++ b/src/Serilog.Sinks.MongoDB/Sinks/MongoDB/LogEntry.cs @@ -1,4 +1,4 @@ -// Copyright 2014-2022 Serilog Contributors +// Copyright 2014-2024 Serilog Contributors // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/src/Serilog.Sinks.MongoDB/Sinks/MongoDB/MongoDBJsonFormatter.cs b/src/Serilog.Sinks.MongoDB/Sinks/MongoDB/MongoDBJsonFormatter.cs index b09a4b6..d7276cb 100644 --- a/src/Serilog.Sinks.MongoDB/Sinks/MongoDB/MongoDBJsonFormatter.cs +++ b/src/Serilog.Sinks.MongoDB/Sinks/MongoDB/MongoDBJsonFormatter.cs @@ -1,4 +1,4 @@ -// Copyright 2014-2022 Serilog Contributors +// Copyright 2014-2024 Serilog Contributors // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/src/Serilog.Sinks.MongoDB/Sinks/MongoDB/MongoDBSink.cs b/src/Serilog.Sinks.MongoDB/Sinks/MongoDB/MongoDBSink.cs index 41a4a7b..725dc4c 100644 --- a/src/Serilog.Sinks.MongoDB/Sinks/MongoDB/MongoDBSink.cs +++ b/src/Serilog.Sinks.MongoDB/Sinks/MongoDB/MongoDBSink.cs @@ -1,4 +1,4 @@ -// Copyright 2014-2022 Serilog Contributors +// Copyright 2014-2024 Serilog Contributors // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -14,9 +14,11 @@ using System; using System.Collections.Generic; +using System.Diagnostics.CodeAnalysis; using System.Linq; using System.Threading.Tasks; +using MongoDB.Bson; using MongoDB.Bson.Serialization; using Serilog.Events; @@ -37,6 +39,10 @@ static MongoDBSink() cm.MapProperty(s => s.StackTrace); cm.MapProperty(s => s.Data); }); + + // fixes https://github.com/serilog/serilog/issues/2101 + BsonTypeMapper.RegisterCustomTypeMapper(typeof(IntPtr), new CustomIntPtrMapper()); + BsonTypeMapper.RegisterCustomTypeMapper(typeof(UIntPtr), new CustomIntPtrMapper()); } public MongoDBSink(MongoDBSinkConfiguration configuration) @@ -46,6 +52,26 @@ public MongoDBSink(MongoDBSinkConfiguration configuration) public override Task EmitBatchAsync(IEnumerable events) { - return this.InsertMany(events.Select(@event => LogEntry.MapFrom(@event, this.IncludeMessageTemplate))); + return this.InsertMany( + events.Select(@event => LogEntry.MapFrom(@event, this.IncludeMessageTemplate))); + } + + private class CustomIntPtrMapper : ICustomBsonTypeMapper + { + public bool TryMapToBsonValue(object value, [UnscopedRef] out BsonValue? bsonValue) + { + switch (value) + { + case IntPtr intPtr: + bsonValue = intPtr.ToInt32(); + return true; + case UIntPtr uIntPtr: + bsonValue = uIntPtr.ToUInt32(); + return true; + default: + bsonValue = null; + return false; + } + } } } \ No newline at end of file diff --git a/src/Serilog.Sinks.MongoDB/Sinks/MongoDB/MongoDBSinkBase.cs b/src/Serilog.Sinks.MongoDB/Sinks/MongoDB/MongoDBSinkBase.cs index fee2678..38f2eec 100644 --- a/src/Serilog.Sinks.MongoDB/Sinks/MongoDB/MongoDBSinkBase.cs +++ b/src/Serilog.Sinks.MongoDB/Sinks/MongoDB/MongoDBSinkBase.cs @@ -1,4 +1,4 @@ -// Copyright 2014-2022 Serilog Contributors +// Copyright 2014-2024 Serilog Contributors // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/src/Serilog.Sinks.MongoDB/Sinks/MongoDB/MongoDBSinkConfiguration.cs b/src/Serilog.Sinks.MongoDB/Sinks/MongoDB/MongoDBSinkConfiguration.cs index 22f1b82..8bf4b46 100644 --- a/src/Serilog.Sinks.MongoDB/Sinks/MongoDB/MongoDBSinkConfiguration.cs +++ b/src/Serilog.Sinks.MongoDB/Sinks/MongoDB/MongoDBSinkConfiguration.cs @@ -1,4 +1,4 @@ -// Copyright 2014-2022 Serilog Contributors +// Copyright 2014-2024 Serilog Contributors // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/src/Serilog.Sinks.MongoDB/Sinks/MongoDB/MongoDBSinkDefaults.cs b/src/Serilog.Sinks.MongoDB/Sinks/MongoDB/MongoDBSinkDefaults.cs index a2717aa..ee56d82 100644 --- a/src/Serilog.Sinks.MongoDB/Sinks/MongoDB/MongoDBSinkDefaults.cs +++ b/src/Serilog.Sinks.MongoDB/Sinks/MongoDB/MongoDBSinkDefaults.cs @@ -1,4 +1,4 @@ -// Copyright 2014-2022 Serilog Contributors +// Copyright 2014-2024 Serilog Contributors // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/src/Serilog.Sinks.MongoDB/Sinks/MongoDB/MongoDBSinkLegacy.cs b/src/Serilog.Sinks.MongoDB/Sinks/MongoDB/MongoDBSinkLegacy.cs index 7fc63a6..9a0491f 100644 --- a/src/Serilog.Sinks.MongoDB/Sinks/MongoDB/MongoDBSinkLegacy.cs +++ b/src/Serilog.Sinks.MongoDB/Sinks/MongoDB/MongoDBSinkLegacy.cs @@ -1,4 +1,4 @@ -// Copyright 2014-2022 Serilog Contributors +// Copyright 2014-2024 Serilog Contributors // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/src/Serilog.Sinks.MongoDB/Sinks/MongoDB/RollingInterval.cs b/src/Serilog.Sinks.MongoDB/Sinks/MongoDB/RollingInterval.cs index 7c1422f..8dd3eb6 100644 --- a/src/Serilog.Sinks.MongoDB/Sinks/MongoDB/RollingInterval.cs +++ b/src/Serilog.Sinks.MongoDB/Sinks/MongoDB/RollingInterval.cs @@ -1,4 +1,4 @@ -// Copyright 2014-2022 Serilog Contributors +// Copyright 2014-2024 Serilog Contributors // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/test/Serilog.Sinks.MongoDB.Tests/Serilog.Sinks.MongoDB.Tests.csproj b/test/Serilog.Sinks.MongoDB.Tests/Serilog.Sinks.MongoDB.Tests.csproj index f7147d0..9586d50 100644 --- a/test/Serilog.Sinks.MongoDB.Tests/Serilog.Sinks.MongoDB.Tests.csproj +++ b/test/Serilog.Sinks.MongoDB.Tests/Serilog.Sinks.MongoDB.Tests.csproj @@ -6,12 +6,12 @@ - + - - - + + +