diff --git a/.github/ISSUE_TEMPLATE/bug_report.md b/.github/ISSUE_TEMPLATE/bug_report.md
index dd84ea7..3205926 100644
--- a/.github/ISSUE_TEMPLATE/bug_report.md
+++ b/.github/ISSUE_TEMPLATE/bug_report.md
@@ -12,6 +12,7 @@ A clear and concise description of what the bug is.
**To Reproduce**
Steps to reproduce the behavior:
+
1. Go to '...'
2. Click on '....'
3. Scroll down to '....'
@@ -24,15 +25,17 @@ A clear and concise description of what you expected to happen.
If applicable, add screenshots to help explain your problem.
**Desktop (please complete the following information):**
- - OS: [e.g. iOS]
- - Browser [e.g. chrome, safari]
- - Version [e.g. 22]
+
+- OS: [e.g. iOS]
+- Browser [e.g. chrome, safari]
+- Version [e.g. 22]
**Smartphone (please complete the following information):**
- - Device: [e.g. iPhone6]
- - OS: [e.g. iOS8.1]
- - Browser [e.g. stock browser, safari]
- - Version [e.g. 22]
+
+- Device: [e.g. iPhone6]
+- OS: [e.g. iOS8.1]
+- Browser [e.g. stock browser, safari]
+- Version [e.g. 22]
**Additional context**
Add any other context about the problem here.
diff --git a/.github/README.md b/.github/README.md
index f46ae03..a42be66 100644
--- a/.github/README.md
+++ b/.github/README.md
@@ -12,19 +12,19 @@
+
+
+Serilog.Sinks.Mongodb.TimeSeries
- Serilog.Sinks.Mongodb.TimeSeries
-
-
- A simple to use sink for Serilog that saves logs in a Mongodb time series collection.
-
- Explore the docs »
-
-
- Report Bug
- ·
- Request Feature
-
+
+ A simple to use sink for Serilog that saves logs in a Mongodb time series collection.
+
+ Explore the docs »
+
+
+ Report Bug
+ ·
+ Request Feature
diff --git a/.github/workflows/codeql-analysis.yml b/.github/workflows/codeql-analysis.yml
index 0b87aea..158575f 100644
--- a/.github/workflows/codeql-analysis.yml
+++ b/.github/workflows/codeql-analysis.yml
@@ -38,39 +38,39 @@ jobs:
# https://docs.github.com/en/free-pro-team@latest/github/finding-security-vulnerabilities-and-errors-in-your-code/configuring-code-scanning#changing-the-languages-that-are-analyzed
steps:
- - name: Checkout repository
- uses: actions/checkout@v3
+ - name: Checkout repository
+ uses: actions/checkout@v3
- - name: Setup .NET SDK
- uses: actions/setup-dotnet@v3
- with:
- dotnet-version: '7.0.x'
+ - name: Setup .NET SDK
+ uses: actions/setup-dotnet@v3
+ with:
+ dotnet-version: '7.0.x'
+
+ # Initializes the CodeQL tools for scanning.
+ - name: Initialize CodeQL
+ uses: github/codeql-action/init@v1
+ with:
+ languages: ${{ matrix.language }}
+ # If you wish to specify custom queries, you can do so here or in a config file.
+ # By default, queries listed here will override any specified in a config file.
+ # Prefix the list here with "+" to use these queries and those in the config file.
+ # queries: ./path/to/local/query, your-org/your-repo/queries@main
+
+ # Autobuild attempts to build any compiled languages (C/C++, C#, or Java).
+ # If this step fails, then you should remove it and run the build manually (see below)
+ - name: Autobuild
+ uses: github/codeql-action/autobuild@v1
+
+ # ℹ️ Command-line programs to run using the OS shell.
+ # 📚 https://git.io/JvXDl
+
+ # ✏️ If the Autobuild fails above, remove it and uncomment the following three lines
+ # and modify them (or add more) to build your code if your project
+ # uses a compiled language
+
+ #- run: |
+ # make bootstrap
+ # make release
- # Initializes the CodeQL tools for scanning.
- - name: Initialize CodeQL
- uses: github/codeql-action/init@v1
- with:
- languages: ${{ matrix.language }}
- # If you wish to specify custom queries, you can do so here or in a config file.
- # By default, queries listed here will override any specified in a config file.
- # Prefix the list here with "+" to use these queries and those in the config file.
- # queries: ./path/to/local/query, your-org/your-repo/queries@main
-
- # Autobuild attempts to build any compiled languages (C/C++, C#, or Java).
- # If this step fails, then you should remove it and run the build manually (see below)
- - name: Autobuild
- uses: github/codeql-action/autobuild@v1
-
- # ℹ️ Command-line programs to run using the OS shell.
- # 📚 https://git.io/JvXDl
-
- # ✏️ If the Autobuild fails above, remove it and uncomment the following three lines
- # and modify them (or add more) to build your code if your project
- # uses a compiled language
-
- #- run: |
- # make bootstrap
- # make release
-
- - name: Perform CodeQL Analysis
- uses: github/codeql-action/analyze@v1
+ - name: Perform CodeQL Analysis
+ uses: github/codeql-action/analyze@v1
diff --git a/.github/workflows/dotnet.yml b/.github/workflows/dotnet.yml
index ab67182..64f7627 100644
--- a/.github/workflows/dotnet.yml
+++ b/.github/workflows/dotnet.yml
@@ -6,7 +6,7 @@ jobs:
runs-on: ${{ matrix.os }}
strategy:
matrix:
- os: [ubuntu-latest]
+ os: [ ubuntu-latest ]
steps:
- name: Checkout
uses: actions/checkout@v1
@@ -16,7 +16,7 @@ jobs:
- name: Setup .NET SDK
uses: actions/setup-dotnet@v3
with:
- dotnet-version: '7.0.x'
+ dotnet-version: '7.0.x'
- name: Install dependencies
run: dotnet restore
diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml
index 30e0b7e..75d5394 100644
--- a/.github/workflows/publish.yml
+++ b/.github/workflows/publish.yml
@@ -2,40 +2,40 @@ name: Publish nuget packages
on:
push:
tags:
- - "v[0-9]+.[0-9]+.[0-9]+"
- - "v[0-9]+.[0-9]+.[0-9]+-alpha"
- - "v[0-9]+.[0-9]+.[0-9]+-beta"
+ - "v[0-9]+.[0-9]+.[0-9]+"
+ - "v[0-9]+.[0-9]+.[0-9]+-alpha"
+ - "v[0-9]+.[0-9]+.[0-9]+-beta"
jobs:
build:
runs-on: ubuntu-latest
timeout-minutes: 15
steps:
- - name: Checkout
- uses: actions/checkout@v3
+ - name: Checkout
+ uses: actions/checkout@v3
- - name: Setup .NET SDK
- uses: actions/setup-dotnet@v3
- with:
- dotnet-version: '7.0.x'
+ - name: Setup .NET SDK
+ uses: actions/setup-dotnet@v3
+ with:
+ dotnet-version: '7.0.x'
- - name: Verify commit exists in origin/main
- run: |
- git fetch --no-tags --prune --depth=1 origin +refs/heads/*:refs/remotes/origin/*
- git branch --remote --contains | grep origin/main
- - name: Set VERSION variable from tag
- run: echo "VERSION=${GITHUB_REF/refs\/tags\/v/}" >> $GITHUB_ENV
+ - name: Verify commit exists in origin/main
+ run: |
+ git fetch --no-tags --prune --depth=1 origin +refs/heads/*:refs/remotes/origin/*
+ git branch --remote --contains | grep origin/main
+ - name: Set VERSION variable from tag
+ run: echo "VERSION=${GITHUB_REF/refs\/tags\/v/}" >> $GITHUB_ENV
- - name: Build Serilog.Sinks.Mongodb.TimeSeries
- run: dotnet build --configuration Release /p:Version=${VERSION}
+ - name: Build Serilog.Sinks.Mongodb.TimeSeries
+ run: dotnet build --configuration Release /p:Version=${VERSION}
- - name: Run unit tests
- run: dotnet test --configuration Release /p:Version=${VERSION} --no-build
+ - name: Run unit tests
+ run: dotnet test --configuration Release /p:Version=${VERSION} --no-build
- - name: Pack Serilog.Sinks.Mongodb.TimeSeries
- run: dotnet pack --configuration Release /p:Version=${VERSION} --no-build --output .
+ - name: Pack Serilog.Sinks.Mongodb.TimeSeries
+ run: dotnet pack --configuration Release /p:Version=${VERSION} --no-build --output .
- - name: Push Serilog.Sinks.Mongodb.TimeSeries github
- run: dotnet nuget push Serilog.Sinks.Mongodb.TimeSeries.${VERSION}.nupkg --source https://nuget.pkg.github.com/brammys/index.json --api-key ${{ secrets.PAT }} --skip-duplicate
+ - name: Push Serilog.Sinks.Mongodb.TimeSeries github
+ run: dotnet nuget push Serilog.Sinks.Mongodb.TimeSeries.${VERSION}.nupkg --source https://nuget.pkg.github.com/brammys/index.json --api-key ${{ secrets.PAT }} --skip-duplicate
- - name: Push Serilog.Sinks.Mongodb.TimeSeries nuget.org
- run: dotnet nuget push Serilog.Sinks.Mongodb.TimeSeries.${VERSION}.nupkg --api-key ${{ secrets.NUGET_TOKEN }} --source https://api.nuget.org/v3/index.json --skip-duplicate
+ - name: Push Serilog.Sinks.Mongodb.TimeSeries nuget.org
+ run: dotnet nuget push Serilog.Sinks.Mongodb.TimeSeries.${VERSION}.nupkg --api-key ${{ secrets.NUGET_TOKEN }} --source https://api.nuget.org/v3/index.json --skip-duplicate
diff --git a/.github/workflows/publishDocs.yml b/.github/workflows/publishDocs.yml
index e2b68f8..5429bbd 100644
--- a/.github/workflows/publishDocs.yml
+++ b/.github/workflows/publishDocs.yml
@@ -2,7 +2,7 @@ name: Publish documentation
on:
push:
tags:
- - "v[0-9]+.[0-9]+.[0-9]+"
+ - "v[0-9]+.[0-9]+.[0-9]+"
jobs:
build:
runs-on: windows-latest
@@ -14,7 +14,7 @@ jobs:
- name: Setup .NET SDK
uses: actions/setup-dotnet@v3
with:
- dotnet-version: '7.0.x'
+ dotnet-version: '7.0.x'
- name: Install dependencies
run: dotnet restore
diff --git a/src/Serilog.Sinks.Mongodb.TimeSeries/Configurations/LogCollectionConfig.cs b/src/Serilog.Sinks.Mongodb.TimeSeries/Configurations/LogCollectionConfig.cs
index d2a9b18..e588e5e 100644
--- a/src/Serilog.Sinks.Mongodb.TimeSeries/Configurations/LogCollectionConfig.cs
+++ b/src/Serilog.Sinks.Mongodb.TimeSeries/Configurations/LogCollectionConfig.cs
@@ -1,28 +1,27 @@
using MongoDB.Bson.Serialization;
using Serilog.Sinks.Mongodb.TimeSeries.Models;
-namespace Serilog.Sinks.Mongodb.TimeSeries.Configurations
+namespace Serilog.Sinks.Mongodb.TimeSeries.Configurations;
+
+///
+/// Holds the mongodb collection configuration for the collection.
+///
+internal static class LogCollectionConfig
{
///
- /// Holds the mongodb collection configuration for the collection.
+ /// Configures the mapping of the object so it can be stored in a collection.
///
- internal static class LogCollectionConfig
+ internal static void ConfigureLogDocumentCollection()
{
- ///
- /// Configures the mapping of the object so it can be stored in a collection.
- ///
- internal static void ConfigureLogDocumentCollection()
+ BsonClassMap.RegisterClassMap(cm =>
{
- BsonClassMap.RegisterClassMap(cm =>
- {
- cm.AutoMap();
- cm.MapField(x => x.Timestamp).SetElementName("timestamp").SetIsRequired(true);
- cm.MapField(x => x.Message).SetElementName("message").SetIsRequired(true);
- cm.MapField(x => x.Properties).SetElementName("properties").SetIsRequired(false);
- cm.MapField(x => x.Severity).SetElementName("severity").SetIsRequired(false);
- cm.MapField(x => x.Exception).SetElementName("exception").SetIsRequired(false).SetIgnoreIfNull(true);
- cm.MapField(x => x.StackTrace).SetElementName("stackTrace").SetIsRequired(false).SetIgnoreIfNull(true);
- });
- }
+ cm.AutoMap();
+ cm.MapField(x => x.Timestamp).SetElementName("timestamp").SetIsRequired(true);
+ cm.MapField(x => x.Message).SetElementName("message").SetIsRequired(true);
+ cm.MapField(x => x.Properties).SetElementName("properties").SetIsRequired(false);
+ cm.MapField(x => x.Severity).SetElementName("severity").SetIsRequired(false);
+ cm.MapField(x => x.Exception).SetElementName("exception").SetIsRequired(false).SetIgnoreIfNull(true);
+ cm.MapField(x => x.StackTrace).SetElementName("stackTrace").SetIsRequired(false).SetIgnoreIfNull(true);
+ });
}
}
\ No newline at end of file
diff --git a/src/Serilog.Sinks.Mongodb.TimeSeries/Configurations/MongoDbTimeSeriesSinkConfig.cs b/src/Serilog.Sinks.Mongodb.TimeSeries/Configurations/MongoDbTimeSeriesSinkConfig.cs
index edf8425..bdcdcb5 100644
--- a/src/Serilog.Sinks.Mongodb.TimeSeries/Configurations/MongoDbTimeSeriesSinkConfig.cs
+++ b/src/Serilog.Sinks.Mongodb.TimeSeries/Configurations/MongoDbTimeSeriesSinkConfig.cs
@@ -1,87 +1,86 @@
using System;
using MongoDB.Driver;
-namespace Serilog.Sinks.Mongodb.TimeSeries.Configurations
+namespace Serilog.Sinks.Mongodb.TimeSeries.Configurations;
+
+///
+/// Contains the configurations for the mongodb serilog sink.
+///
+public record MongoDbTimeSeriesSinkConfig
{
+ private const string TimeSeriesPropertyName = "timestamp";
+
///
- /// Contains the configurations for the mongodb serilog sink.
+ /// Initializes a new .
///
- public record MongoDbTimeSeriesSinkConfig
+ /// The of where the `logs` collection will be stored.
+ public MongoDbTimeSeriesSinkConfig(IMongoDatabase database)
{
- private const string TimeSeriesPropertyName = "timestamp";
+ Database = database;
+ }
- ///
- /// Initializes a new .
- ///
- /// The of where the `logs` collection will be stored.
- public MongoDbTimeSeriesSinkConfig(IMongoDatabase database)
- {
- Database = database;
- }
+ ///
+ /// The collection name of where the logs will be stored. The default is "logs".
+ ///
+ public string CollectionName { get; init; } = "logs";
- ///
- /// The collection name of where the logs will be stored. The default is "logs".
- ///
- public string CollectionName { get; init; } = "logs";
+ ///
+ /// The maximum number of log events to include in a single batch. The default is 1000.
+ ///
+ public int BatchSizeLimit { get; init; } = 1000;
- ///
- /// The maximum number of log events to include in a single batch. The default is 1000.
- ///
- public int BatchSizeLimit { get; init; } = 1000;
+ ///
+ /// Maximum number of events to hold in the sink's internal queue, or null for an unbounded queue. The default is
+ /// 10000.
+ ///
+ public int QueueLimit { get; init; } = 10000;
- ///
- /// Maximum number of events to hold in the sink's internal queue, or null for an unbounded queue. The default is
- /// 10000.
- ///
- public int QueueLimit { get; init; } = 10000;
+ ///
+ /// Eagerly emit a batch containing the first received event, regardless of the target batch size or batching time.
+ /// This helps with perceived "liveness" when running/debugging applications interactively. The default is true.
+ ///
+ public bool EagerlyEmitFirstEvent { get; init; } = true;
- ///
- /// Eagerly emit a batch containing the first received event, regardless of the target batch size or batching time.
- /// This helps with perceived "liveness" when running/debugging applications interactively. The default is true.
- ///
- public bool EagerlyEmitFirstEvent { get; init; } = true;
+ ///
+ /// The time to wait between checking for event batches. The default is 5 seconds.
+ ///
+ public TimeSpan SyncingPeriod { get; init; } = TimeSpan.FromSeconds(5);
- ///
- /// The time to wait between checking for event batches. The default is 5 seconds.
- ///
- public TimeSpan SyncingPeriod { get; init; } = TimeSpan.FromSeconds(5);
+ ///
+ /// The coarse granularity of time-series data. The default is Seconds.
+ ///
+ public TimeSeriesGranularity TimeSeriesGranularity { get; init; } = TimeSeriesGranularity.Seconds;
- ///
- /// The coarse granularity of time-series data. The default is Seconds.
- ///
- public TimeSeriesGranularity TimeSeriesGranularity { get; init; } = TimeSeriesGranularity.Seconds;
+ ///
+ /// Gets or sets a timespan indicating how long documents in a time series collection should be retained.
+ ///
+ public TimeSpan? LogsExpireAfter { get; init; }
- ///
- /// Gets or sets a timespan indicating how long documents in a time series collection should be retained.
- ///
- public TimeSpan? LogsExpireAfter { get; init; }
+ ///
+ /// The that will be used to create a new collection
+ /// when no collection with the name of exists.
+ ///
+ internal CreateCollectionOptions CreateCollectionOptions => DefaultCreateCollectionOptions();
- ///
- /// The that will be used to create a new collection
- /// when no collection with the name of exists.
- ///
- internal CreateCollectionOptions CreateCollectionOptions => DefaultCreateCollectionOptions();
+ ///
+ /// The of where the collection will be stored..
+ ///
+ internal IMongoDatabase Database { get; init; }
- ///
- /// The of where the collection will be stored..
- ///
- internal IMongoDatabase Database { get; init; }
+ ///
+ /// Get a default implementation of .
+ ///
+ ///
+ /// A default implementation of .
+ ///
+ private CreateCollectionOptions DefaultCreateCollectionOptions()
+ {
+ var defaultTimeSeriesOptions = new TimeSeriesOptions(TimeSeriesPropertyName, null, TimeSeriesGranularity);
- ///
- /// Get a default implementation of .
- ///
- ///
- /// A default implementation of .
- ///
- private CreateCollectionOptions DefaultCreateCollectionOptions()
+ return new CreateCollectionOptions
{
- var defaultTimeSeriesOptions = new TimeSeriesOptions(TimeSeriesPropertyName, null, TimeSeriesGranularity);
-
- return new CreateCollectionOptions
- {
- TimeSeriesOptions = defaultTimeSeriesOptions,
- ExpireAfter = LogsExpireAfter
- };
- }
+ TimeSeriesOptions = defaultTimeSeriesOptions,
+ ExpireAfter = LogsExpireAfter
+ };
}
}
\ No newline at end of file
diff --git a/src/Serilog.Sinks.Mongodb.TimeSeries/Extensions/LogEventExtensions.cs b/src/Serilog.Sinks.Mongodb.TimeSeries/Extensions/LogEventExtensions.cs
index 269e5e3..b96fd61 100644
--- a/src/Serilog.Sinks.Mongodb.TimeSeries/Extensions/LogEventExtensions.cs
+++ b/src/Serilog.Sinks.Mongodb.TimeSeries/Extensions/LogEventExtensions.cs
@@ -4,48 +4,47 @@
using Serilog.Events;
using Serilog.Sinks.Mongodb.TimeSeries.Models;
-namespace Serilog.Sinks.Mongodb.TimeSeries.Extensions
+namespace Serilog.Sinks.Mongodb.TimeSeries.Extensions;
+
+///
+/// Contains all extensions methods for .
+///
+internal static class LogEventExtensions
{
///
- /// Contains all extensions methods for .
+ /// Converts a of s to of
+ /// s.
///
- internal static class LogEventExtensions
+ /// The log events that will be converted.
+ /// Supplies culture-specific formatting information, or null.
+ ///
+ /// The converted of s.
+ ///
+ internal static IEnumerable ToDocuments(this IEnumerable logEvents, IFormatProvider? formatProvider = null)
{
- ///
- /// Converts a of s to of
- /// s.
- ///
- /// The log events that will be converted.
- /// Supplies culture-specific formatting information, or null.
- ///
- /// The converted of s.
- ///
- internal static IEnumerable ToDocuments(this IEnumerable logEvents, IFormatProvider? formatProvider = null)
+ var logs = new List();
+
+ foreach (var logEvent in logEvents)
{
- var logs = new List();
+ var message = logEvent.RenderMessage(formatProvider);
+ var properties = new Dictionary();
- foreach (var logEvent in logEvents)
+ foreach (var (key, value) in logEvent.Properties)
{
- var message = logEvent.RenderMessage(formatProvider);
- var properties = new Dictionary();
-
- foreach (var (key, value) in logEvent.Properties)
- {
- properties.Add(key.ToSaveAbleString(), value.ToBsonValue(null, formatProvider));
- }
-
- logs.Add(new LogDocument
- {
- Exception = logEvent.Exception,
- StackTrace = logEvent.Exception?.StackTrace,
- Severity = logEvent.Level.ToSeverityString(),
- Properties = properties,
- Timestamp = logEvent.Timestamp.UtcDateTime,
- Message = message
- });
+ properties.Add(key.ToSaveAbleString(), value.ToBsonValue(null, formatProvider));
}
- return logs;
+ logs.Add(new LogDocument
+ {
+ Exception = logEvent.Exception,
+ StackTrace = logEvent.Exception?.StackTrace,
+ Severity = logEvent.Level.ToSeverityString(),
+ Properties = properties,
+ Timestamp = logEvent.Timestamp.UtcDateTime,
+ Message = message
+ });
}
+
+ return logs;
}
}
\ No newline at end of file
diff --git a/src/Serilog.Sinks.Mongodb.TimeSeries/Extensions/LogEventLevelExtensions.cs b/src/Serilog.Sinks.Mongodb.TimeSeries/Extensions/LogEventLevelExtensions.cs
index aa36841..394e082 100644
--- a/src/Serilog.Sinks.Mongodb.TimeSeries/Extensions/LogEventLevelExtensions.cs
+++ b/src/Serilog.Sinks.Mongodb.TimeSeries/Extensions/LogEventLevelExtensions.cs
@@ -1,43 +1,42 @@
using System;
using Serilog.Events;
-namespace Serilog.Sinks.Mongodb.TimeSeries.Extensions
+namespace Serilog.Sinks.Mongodb.TimeSeries.Extensions;
+
+///
+/// Contains all extensions methods for .
+///
+internal static class LogEventLevelExtensions
{
+ private const string Verbose = "verbose";
+ private const string Debug = "debug";
+ private const string Information = "information";
+ private const string Warning = "warning";
+ private const string Error = "error";
+ private const string Fatal = "fatal";
+
///
- /// Contains all extensions methods for .
+ /// Converts a into a readable .
///
- internal static class LogEventLevelExtensions
+ /// The .
+ ///
+ /// The readable containing the severity.
+ ///
+ ///
+ /// Thrown when no severity string was found for the current
+ /// .
+ ///
+ internal static string ToSeverityString(this LogEventLevel level)
{
- private const string Verbose = "verbose";
- private const string Debug = "debug";
- private const string Information = "information";
- private const string Warning = "warning";
- private const string Error = "error";
- private const string Fatal = "fatal";
-
- ///
- /// Converts a into a readable .
- ///
- /// The .
- ///
- /// The readable containing the severity.
- ///
- ///
- /// Thrown when no severity string was found for the current
- /// .
- ///
- internal static string ToSeverityString(this LogEventLevel level)
+ return level switch
{
- return level switch
- {
- LogEventLevel.Verbose => Verbose,
- LogEventLevel.Debug => Debug,
- LogEventLevel.Information => Information,
- LogEventLevel.Warning => Warning,
- LogEventLevel.Error => Error,
- LogEventLevel.Fatal => Fatal,
- _ => throw new ArgumentOutOfRangeException(nameof(level), level, null)
- };
- }
+ LogEventLevel.Verbose => Verbose,
+ LogEventLevel.Debug => Debug,
+ LogEventLevel.Information => Information,
+ LogEventLevel.Warning => Warning,
+ LogEventLevel.Error => Error,
+ LogEventLevel.Fatal => Fatal,
+ _ => throw new ArgumentOutOfRangeException(nameof(level), level, null)
+ };
}
}
\ No newline at end of file
diff --git a/src/Serilog.Sinks.Mongodb.TimeSeries/Extensions/LogEventPropertyValueExtensions.cs b/src/Serilog.Sinks.Mongodb.TimeSeries/Extensions/LogEventPropertyValueExtensions.cs
index 624811a..0ea75bf 100644
--- a/src/Serilog.Sinks.Mongodb.TimeSeries/Extensions/LogEventPropertyValueExtensions.cs
+++ b/src/Serilog.Sinks.Mongodb.TimeSeries/Extensions/LogEventPropertyValueExtensions.cs
@@ -3,75 +3,74 @@
using MongoDB.Bson;
using Serilog.Events;
-namespace Serilog.Sinks.Mongodb.TimeSeries.Extensions
+namespace Serilog.Sinks.Mongodb.TimeSeries.Extensions;
+
+///
+/// Contains all extensions methods for .
+///
+internal static class LogEventPropertyValueExtensions
{
///
- /// Contains all extensions methods for .
+ /// Converts the to a
///
- internal static class LogEventPropertyValueExtensions
+ /// The value to convert (possibly null).
+ /// A format string applied to the value, or null.
+ /// A format provider to apply to the value, or null to use the default.
+ ///
+ /// The converted .
+ ///
+ internal static BsonValue ToBsonValue(this LogEventPropertyValue propertyValue, string? format = null, IFormatProvider? formatProvider = null)
{
- ///
- /// Converts the to a
- ///
- /// The value to convert (possibly null).
- /// A format string applied to the value, or null.
- /// A format provider to apply to the value, or null to use the default.
- ///
- /// The converted .
- ///
- internal static BsonValue ToBsonValue(this LogEventPropertyValue propertyValue, string? format = null, IFormatProvider? formatProvider = null)
+ if (propertyValue is ScalarValue scalar)
{
- if (propertyValue is ScalarValue scalar)
- {
- return ConvertScalar(scalar.Value);
- }
+ return ConvertScalar(scalar.Value);
+ }
- if (propertyValue is DictionaryValue dict)
+ if (propertyValue is DictionaryValue dict)
+ {
+ var bsonDict = new Dictionary();
+ foreach (var (key, value) in dict.Elements)
{
- var bsonDict = new Dictionary();
- foreach (var (key, value) in dict.Elements)
- {
- bsonDict.Add(ConvertScalar(key), value.ToBsonValue(format, formatProvider));
- }
-
- return BsonValue.Create(bsonDict);
+ bsonDict.Add(ConvertScalar(key), value.ToBsonValue(format, formatProvider));
}
- if (propertyValue is SequenceValue seq)
- {
- var bsonList = new List();
- foreach (var value in seq.Elements)
- {
- bsonList.Add(value.ToBsonValue(format, formatProvider));
- }
-
- return BsonValue.Create(bsonList);
- }
+ return BsonValue.Create(bsonDict);
+ }
- if (propertyValue is StructureValue str)
+ if (propertyValue is SequenceValue seq)
+ {
+ var bsonList = new List();
+ foreach (var value in seq.Elements)
{
- return BsonValue.Create(str.ToString(format, formatProvider));
+ bsonList.Add(value.ToBsonValue(format, formatProvider));
}
- return BsonValue.Create(null);
+ return BsonValue.Create(bsonList);
}
- private static BsonValue ConvertScalar(object? value)
+ if (propertyValue is StructureValue str)
{
- if (value is null) return BsonValue.Create(null);
+ return BsonValue.Create(str.ToString(format, formatProvider));
+ }
+
+ return BsonValue.Create(null);
+ }
+
+ private static BsonValue ConvertScalar(object? value)
+ {
+ if (value is null) return BsonValue.Create(null);
- var valueType = value.GetType();
+ var valueType = value.GetType();
- if (valueType == typeof(string)) return BsonValue.Create((string)value);
- if (valueType == typeof(byte[])) return BsonValue.Create((byte[])value);
- if (valueType == typeof(int)) return BsonValue.Create((int)value);
- if (valueType == typeof(long)) return BsonValue.Create((long)value);
- if (valueType == typeof(bool)) return BsonValue.Create((bool)value);
- if (valueType == typeof(double)) return BsonValue.Create((double)value);
- if (valueType == typeof(DateTimeOffset)) return BsonValue.Create(((DateTimeOffset)value).Date);
- if (valueType == typeof(DateTime)) return BsonValue.Create((DateTime)value);
+ if (valueType == typeof(string)) return BsonValue.Create((string)value);
+ if (valueType == typeof(byte[])) return BsonValue.Create((byte[])value);
+ if (valueType == typeof(int)) return BsonValue.Create((int)value);
+ if (valueType == typeof(long)) return BsonValue.Create((long)value);
+ if (valueType == typeof(bool)) return BsonValue.Create((bool)value);
+ if (valueType == typeof(double)) return BsonValue.Create((double)value);
+ if (valueType == typeof(DateTimeOffset)) return BsonValue.Create(((DateTimeOffset)value).Date);
+ if (valueType == typeof(DateTime)) return BsonValue.Create((DateTime)value);
- return BsonValue.Create(value.ToString());
- }
+ return BsonValue.Create(value.ToString());
}
}
\ No newline at end of file
diff --git a/src/Serilog.Sinks.Mongodb.TimeSeries/Extensions/LoggerSinkConfigurationExtensions.cs b/src/Serilog.Sinks.Mongodb.TimeSeries/Extensions/LoggerSinkConfigurationExtensions.cs
index af7e4ee..84f0728 100644
--- a/src/Serilog.Sinks.Mongodb.TimeSeries/Extensions/LoggerSinkConfigurationExtensions.cs
+++ b/src/Serilog.Sinks.Mongodb.TimeSeries/Extensions/LoggerSinkConfigurationExtensions.cs
@@ -4,50 +4,49 @@
using Serilog.Sinks.Mongodb.TimeSeries.Configurations;
using Serilog.Sinks.PeriodicBatching;
-namespace Serilog.Sinks.Mongodb.TimeSeries.Extensions
+namespace Serilog.Sinks.Mongodb.TimeSeries.Extensions;
+
+///
+/// Makes the WriteTo.MongoDbTimeSeriesSink() extension method available to .
+///
+public static class LoggerSinkConfigurationExtensions
{
///
- /// Makes the WriteTo.MongoDbTimeSeriesSink() extension method available to .
+ /// Registers the MongoDb time series sink to the logger.
///
- public static class LoggerSinkConfigurationExtensions
+ /// The .
+ /// The configurations the the mongodb time series sink will use.
+ /// Supplies culture-specific formatting information, or null.
+ ///
+ /// The new with the new sink.
+ ///
+ public static LoggerConfiguration MongoDbTimeSeriesSink(this LoggerSinkConfiguration loggerConfiguration, MongoDbTimeSeriesSinkConfig sinkConfig, IFormatProvider? formatProvider = null)
{
- ///
- /// Registers the MongoDb time series sink to the logger.
- ///
- /// The .
- /// The configurations the the mongodb time series sink will use.
- /// Supplies culture-specific formatting information, or null.
- ///
- /// The new with the new sink.
- ///
- public static LoggerConfiguration MongoDbTimeSeriesSink(this LoggerSinkConfiguration loggerConfiguration, MongoDbTimeSeriesSinkConfig sinkConfig, IFormatProvider? formatProvider = null)
+ var batchingOptions = new PeriodicBatchingSinkOptions
{
- var batchingOptions = new PeriodicBatchingSinkOptions
- {
- Period = sinkConfig.SyncingPeriod,
- QueueLimit = sinkConfig.QueueLimit,
- BatchSizeLimit = sinkConfig.BatchSizeLimit,
- EagerlyEmitFirstEvent = sinkConfig.EagerlyEmitFirstEvent
- };
+ Period = sinkConfig.SyncingPeriod,
+ QueueLimit = sinkConfig.QueueLimit,
+ BatchSizeLimit = sinkConfig.BatchSizeLimit,
+ EagerlyEmitFirstEvent = sinkConfig.EagerlyEmitFirstEvent
+ };
- var logSink = new MongoDbTimeSink(sinkConfig, formatProvider);
+ var logSink = new MongoDbTimeSink(sinkConfig, formatProvider);
- var batchingMongoDbSink = new PeriodicBatchingSink(logSink, batchingOptions);
- return loggerConfiguration.Sink(batchingMongoDbSink);
- }
+ var batchingMongoDbSink = new PeriodicBatchingSink(logSink, batchingOptions);
+ return loggerConfiguration.Sink(batchingMongoDbSink);
+ }
- ///
- /// Registers the MongoDb time series sink to the logger.
- ///
- /// The .
- /// The database of where the logs will be stored.
- /// Supplies culture-specific formatting information, or null.
- ///
- /// The new with the new sink.
- ///
- public static LoggerConfiguration MongoDbTimeSeriesSink(this LoggerSinkConfiguration loggerConfiguration, IMongoDatabase database, IFormatProvider? formatProvider = null)
- {
- return MongoDbTimeSeriesSink(loggerConfiguration, new MongoDbTimeSeriesSinkConfig(database), formatProvider);
- }
+ ///
+ /// Registers the MongoDb time series sink to the logger.
+ ///
+ /// The .
+ /// The database of where the logs will be stored.
+ /// Supplies culture-specific formatting information, or null.
+ ///
+ /// The new with the new sink.
+ ///
+ public static LoggerConfiguration MongoDbTimeSeriesSink(this LoggerSinkConfiguration loggerConfiguration, IMongoDatabase database, IFormatProvider? formatProvider = null)
+ {
+ return MongoDbTimeSeriesSink(loggerConfiguration, new MongoDbTimeSeriesSinkConfig(database), formatProvider);
}
}
\ No newline at end of file
diff --git a/src/Serilog.Sinks.Mongodb.TimeSeries/Extensions/MongoDatabaseExtensions.cs b/src/Serilog.Sinks.Mongodb.TimeSeries/Extensions/MongoDatabaseExtensions.cs
index 684cfa9..de856c0 100644
--- a/src/Serilog.Sinks.Mongodb.TimeSeries/Extensions/MongoDatabaseExtensions.cs
+++ b/src/Serilog.Sinks.Mongodb.TimeSeries/Extensions/MongoDatabaseExtensions.cs
@@ -1,26 +1,25 @@
using MongoDB.Bson;
using MongoDB.Driver;
-namespace Serilog.Sinks.Mongodb.TimeSeries.Extensions
+namespace Serilog.Sinks.Mongodb.TimeSeries.Extensions;
+
+///
+/// Contains all extensions methods for .
+///
+internal static class MongoDatabaseExtensions
{
///
- /// Contains all extensions methods for .
+ /// Checks whether or not a collection exists.
///
- internal static class MongoDatabaseExtensions
+ /// The .
+ /// The collection name that will be checked whether or not it exists.
+ ///
+ /// Whether or not a collection exists..
+ ///
+ internal static bool CollectionExists(this IMongoDatabase database, string collectionName)
{
- ///
- /// Checks whether or not a collection exists.
- ///
- /// The .
- /// The collection name that will be checked whether or not it exists.
- ///
- /// Whether or not a collection exists..
- ///
- internal static bool CollectionExists(this IMongoDatabase database, string collectionName)
- {
- var filter = new BsonDocument("name", collectionName);
- var collectionCursor = database.ListCollections(new ListCollectionsOptions { Filter = filter });
- return collectionCursor.Any();
- }
+ var filter = new BsonDocument("name", collectionName);
+ var collectionCursor = database.ListCollections(new ListCollectionsOptions { Filter = filter });
+ return collectionCursor.Any();
}
}
\ No newline at end of file
diff --git a/src/Serilog.Sinks.Mongodb.TimeSeries/Extensions/StringExtensions.cs b/src/Serilog.Sinks.Mongodb.TimeSeries/Extensions/StringExtensions.cs
index 5534e09..0a6c8df 100644
--- a/src/Serilog.Sinks.Mongodb.TimeSeries/Extensions/StringExtensions.cs
+++ b/src/Serilog.Sinks.Mongodb.TimeSeries/Extensions/StringExtensions.cs
@@ -1,26 +1,25 @@
-namespace Serilog.Sinks.Mongodb.TimeSeries.Extensions
+namespace Serilog.Sinks.Mongodb.TimeSeries.Extensions;
+
+///
+/// Contains all extensions methods for .
+///
+internal static class StringExtensions
{
+ private const string NullTag = "[NULL]";
+ private const char DotChar = '.';
+ private const char LineChar = '-';
+ private const char DollarChar = '$';
+ private const char UnderscoreChar = '_';
+
///
- /// Contains all extensions methods for .
+ /// Turn a into a savable string.
///
- internal static class StringExtensions
+ /// The data.
+ ///
+ /// The savable .
+ ///
+ internal static string ToSaveAbleString(this string? data)
{
- private const string NullTag = "[NULL]";
- private const char DotChar = '.';
- private const char LineChar = '-';
- private const char DollarChar = '$';
- private const char UnderscoreChar = '_';
-
- ///
- /// Turn a into a savable string.
- ///
- /// The data.
- ///
- /// The savable .
- ///
- internal static string ToSaveAbleString(this string? data)
- {
- return data == null ? NullTag : data.Replace(DotChar, LineChar).Replace(DollarChar, UnderscoreChar);
- }
+ return data == null ? NullTag : data.Replace(DotChar, LineChar).Replace(DollarChar, UnderscoreChar);
}
}
\ No newline at end of file
diff --git a/src/Serilog.Sinks.Mongodb.TimeSeries/Models/LogDocument.cs b/src/Serilog.Sinks.Mongodb.TimeSeries/Models/LogDocument.cs
index 97f50ce..51b3349 100644
--- a/src/Serilog.Sinks.Mongodb.TimeSeries/Models/LogDocument.cs
+++ b/src/Serilog.Sinks.Mongodb.TimeSeries/Models/LogDocument.cs
@@ -2,41 +2,40 @@
using System.Collections.Generic;
using MongoDB.Bson;
-namespace Serilog.Sinks.Mongodb.TimeSeries.Models
+namespace Serilog.Sinks.Mongodb.TimeSeries.Models;
+
+///
+/// The document that will be stored in mongodb.
+///
+public class LogDocument
{
///
- /// The document that will be stored in mongodb.
+ /// Properties associated with the event, including those presented in .
///
- public class LogDocument
- {
- ///
- /// Properties associated with the event, including those presented in .
- ///
- public Dictionary Properties { get; init; } = null!;
+ public Dictionary Properties { get; init; } = null!;
- ///
- /// The time at which the event occurred.
- ///
- public DateTime Timestamp { get; init; }
+ ///
+ /// The time at which the event occurred.
+ ///
+ public DateTime Timestamp { get; init; }
- ///
- /// The log level severity.
- ///
- public string Severity { get; init; } = null!;
+ ///
+ /// The log level severity.
+ ///
+ public string Severity { get; init; } = null!;
- ///
- /// The message template describing the event.
- ///
- public string Message { get; init; } = null!;
+ ///
+ /// The message template describing the event.
+ ///
+ public string Message { get; init; } = null!;
- ///
- /// An exception associated with the event, or null.
- ///
- public Exception? Exception { get; init; }
+ ///
+ /// An exception associated with the event, or null.
+ ///
+ public Exception? Exception { get; init; }
- ///
- /// The stack trace of the error, or null.
- ///
- public string? StackTrace { get; init; }
- }
+ ///
+ /// The stack trace of the error, or null.
+ ///
+ public string? StackTrace { get; init; }
}
\ No newline at end of file
diff --git a/src/Serilog.Sinks.Mongodb.TimeSeries/MongoDbTimeSink.cs b/src/Serilog.Sinks.Mongodb.TimeSeries/MongoDbTimeSink.cs
index 919c760..0d2cb1e 100644
--- a/src/Serilog.Sinks.Mongodb.TimeSeries/MongoDbTimeSink.cs
+++ b/src/Serilog.Sinks.Mongodb.TimeSeries/MongoDbTimeSink.cs
@@ -8,42 +8,41 @@
using Serilog.Sinks.Mongodb.TimeSeries.Models;
using Serilog.Sinks.PeriodicBatching;
-namespace Serilog.Sinks.Mongodb.TimeSeries
+namespace Serilog.Sinks.Mongodb.TimeSeries;
+
+///
+/// Saves batches of s to the mongodb database.
+///
+internal class MongoDbTimeSink : IBatchedLogEventSink
{
+ private readonly IMongoCollection _collection;
+ private readonly IFormatProvider? _formatProvider;
+
///
- /// Saves batches of s to the mongodb database.
+ /// Initializes a new .
///
- internal class MongoDbTimeSink : IBatchedLogEventSink
+ /// The that will be used to configure the Mongodb sink.
+ /// Supplies culture-specific formatting information, or null.
+ internal MongoDbTimeSink(MongoDbTimeSeriesSinkConfig config, IFormatProvider? formatProvider = null)
{
- private readonly IMongoCollection _collection;
- private readonly IFormatProvider? _formatProvider;
+ _formatProvider = formatProvider;
+ if (!config.Database.CollectionExists(config.CollectionName)) config.Database.CreateCollection(config.CollectionName, config.CreateCollectionOptions);
- ///
- /// Initializes a new .
- ///
- /// The that will be used to configure the Mongodb sink.
- /// Supplies culture-specific formatting information, or null.
- internal MongoDbTimeSink(MongoDbTimeSeriesSinkConfig config, IFormatProvider? formatProvider = null)
- {
- _formatProvider = formatProvider;
- if (!config.Database.CollectionExists(config.CollectionName)) config.Database.CreateCollection(config.CollectionName, config.CreateCollectionOptions);
+ LogCollectionConfig.ConfigureLogDocumentCollection();
- LogCollectionConfig.ConfigureLogDocumentCollection();
-
- _collection = config.Database.GetCollection(config.CollectionName);
- }
+ _collection = config.Database.GetCollection(config.CollectionName);
+ }
- ///
- public async Task EmitBatchAsync(IEnumerable batch)
- {
- var logs = batch.ToDocuments(_formatProvider);
- await _collection.InsertManyAsync(logs).ConfigureAwait(false);
- }
+ ///
+ public async Task EmitBatchAsync(IEnumerable batch)
+ {
+ var logs = batch.ToDocuments(_formatProvider);
+ await _collection.InsertManyAsync(logs).ConfigureAwait(false);
+ }
- ///
- public Task OnEmptyBatchAsync()
- {
- return Task.CompletedTask;
- }
+ ///
+ public Task OnEmptyBatchAsync()
+ {
+ return Task.CompletedTask;
}
}
\ No newline at end of file
diff --git a/src/Serilog.Sinks.Mongodb.TimeSeries/Serilog.Sinks.Mongodb.TimeSeries.csproj b/src/Serilog.Sinks.Mongodb.TimeSeries/Serilog.Sinks.Mongodb.TimeSeries.csproj
index f08f8ff..31107db 100644
--- a/src/Serilog.Sinks.Mongodb.TimeSeries/Serilog.Sinks.Mongodb.TimeSeries.csproj
+++ b/src/Serilog.Sinks.Mongodb.TimeSeries/Serilog.Sinks.Mongodb.TimeSeries.csproj
@@ -1,18 +1,17 @@
- net7.0
+ net7.0;netstandard2.1
+ 11.0
Serilog.Sinks.Mongodb.TimeSeries
enable
-
-
-
-
-
-
+
+
+
+
@@ -50,7 +49,7 @@
-
+
diff --git a/tests/Serilog.Sinks.Mongodb.TimeSeries.Tests/Configurations/LogCollectionConfigTests.cs b/tests/Serilog.Sinks.Mongodb.TimeSeries.Tests/Configurations/LogCollectionConfigTests.cs
index f193af0..6ec21a8 100644
--- a/tests/Serilog.Sinks.Mongodb.TimeSeries.Tests/Configurations/LogCollectionConfigTests.cs
+++ b/tests/Serilog.Sinks.Mongodb.TimeSeries.Tests/Configurations/LogCollectionConfigTests.cs
@@ -4,19 +4,18 @@
using Serilog.Sinks.Mongodb.TimeSeries.Configurations;
using Serilog.Sinks.Mongodb.TimeSeries.Models;
-namespace Serilog.Sinks.Mongodb.TimeSeries.Tests.Configurations
+namespace Serilog.Sinks.Mongodb.TimeSeries.Tests.Configurations;
+
+[TestFixture]
+public class BaseDocumentCollectionConfiguratorTests
{
- [TestFixture]
- public class BaseDocumentCollectionConfiguratorTests
+ [Test]
+ public static void ShouldConfigureLogCollection()
{
- [Test]
- public static void ShouldConfigureLogCollection()
- {
- // Act
- LogCollectionConfig.ConfigureLogDocumentCollection();
+ // Act
+ LogCollectionConfig.ConfigureLogDocumentCollection();
- // Assert
- BsonClassMap.IsClassMapRegistered(typeof(LogDocument)).Should().BeTrue();
- }
+ // Assert
+ BsonClassMap.IsClassMapRegistered(typeof(LogDocument)).Should().BeTrue();
}
}
\ No newline at end of file
diff --git a/tests/Serilog.Sinks.Mongodb.TimeSeries.Tests/Configurations/MongoDbTimeSeriesSinkConfigTests.cs b/tests/Serilog.Sinks.Mongodb.TimeSeries.Tests/Configurations/MongoDbTimeSeriesSinkConfigTests.cs
index c41acd7..5a5f0c1 100644
--- a/tests/Serilog.Sinks.Mongodb.TimeSeries.Tests/Configurations/MongoDbTimeSeriesSinkConfigTests.cs
+++ b/tests/Serilog.Sinks.Mongodb.TimeSeries.Tests/Configurations/MongoDbTimeSeriesSinkConfigTests.cs
@@ -5,66 +5,65 @@
using NUnit.Framework;
using Serilog.Sinks.Mongodb.TimeSeries.Configurations;
-namespace Serilog.Sinks.Mongodb.TimeSeries.Tests.Configurations
+namespace Serilog.Sinks.Mongodb.TimeSeries.Tests.Configurations;
+
+[TestFixture]
+public class MongoDbTimeSeriesSinkConfigTests
{
- [TestFixture]
- public class MongoDbTimeSeriesSinkConfigTests
+ [Test]
+ public void Config_should_contains_defaults()
{
- [Test]
- public void Config_should_contains_defaults()
- {
- // Arrange
- var mockDb = new Mock();
-
- // Act
- var config = new MongoDbTimeSeriesSinkConfig(mockDb.Object);
-
- // Assert
- config.CollectionName.Should().Be("logs");
- config.BatchSizeLimit.Should().Be(1000);
- config.QueueLimit.Should().Be(10000);
- config.EagerlyEmitFirstEvent.Should().Be(true);
- config.SyncingPeriod.Should().Be(TimeSpan.FromSeconds(5));
- config.TimeSeriesGranularity.Should().Be(TimeSeriesGranularity.Seconds);
- config.LogsExpireAfter.Should().BeNull();
-
- config.CreateCollectionOptions.ExpireAfter.Should().BeNull();
- config.CreateCollectionOptions.MaxDocuments.Should().BeNull();
- config.CreateCollectionOptions.MaxSize.Should().BeNull();
- config.CreateCollectionOptions.TimeSeriesOptions.Granularity.Should().Be(TimeSeriesGranularity.Seconds);
- config.CreateCollectionOptions.TimeSeriesOptions.TimeField.Should().Be("timestamp");
- }
-
- [Test]
- public void Config_should_contains_custom_values()
+ // Arrange
+ var mockDb = new Mock();
+
+ // Act
+ var config = new MongoDbTimeSeriesSinkConfig(mockDb.Object);
+
+ // Assert
+ config.CollectionName.Should().Be("logs");
+ config.BatchSizeLimit.Should().Be(1000);
+ config.QueueLimit.Should().Be(10000);
+ config.EagerlyEmitFirstEvent.Should().Be(true);
+ config.SyncingPeriod.Should().Be(TimeSpan.FromSeconds(5));
+ config.TimeSeriesGranularity.Should().Be(TimeSeriesGranularity.Seconds);
+ config.LogsExpireAfter.Should().BeNull();
+
+ config.CreateCollectionOptions.ExpireAfter.Should().BeNull();
+ config.CreateCollectionOptions.MaxDocuments.Should().BeNull();
+ config.CreateCollectionOptions.MaxSize.Should().BeNull();
+ config.CreateCollectionOptions.TimeSeriesOptions.Granularity.Should().Be(TimeSeriesGranularity.Seconds);
+ config.CreateCollectionOptions.TimeSeriesOptions.TimeField.Should().Be("timestamp");
+ }
+
+ [Test]
+ public void Config_should_contains_custom_values()
+ {
+ // Arrange
+ var mockDb = new Mock();
+
+ // Act
+ var config = new MongoDbTimeSeriesSinkConfig(mockDb.Object)
{
- // Arrange
- var mockDb = new Mock();
-
- // Act
- var config = new MongoDbTimeSeriesSinkConfig(mockDb.Object)
- {
- CollectionName = "Logs",
- BatchSizeLimit = 50,
- QueueLimit = 100,
- EagerlyEmitFirstEvent = false,
- SyncingPeriod = TimeSpan.FromSeconds(4),
- TimeSeriesGranularity = TimeSeriesGranularity.Hours,
- LogsExpireAfter = TimeSpan.FromMilliseconds(100)
- };
-
- // Assert
- config.CollectionName.Should().Be("Logs");
- config.BatchSizeLimit.Should().Be(50);
- config.QueueLimit.Should().Be(100);
- config.EagerlyEmitFirstEvent.Should().Be(false);
- config.SyncingPeriod.Should().Be(TimeSpan.FromSeconds(4));
- config.TimeSeriesGranularity.Should().Be(TimeSeriesGranularity.Hours);
- config.LogsExpireAfter.Should().Be(TimeSpan.FromMilliseconds(100));
-
- config.CreateCollectionOptions.ExpireAfter.Should().Be(TimeSpan.FromMilliseconds(100));
- config.CreateCollectionOptions.TimeSeriesOptions.Granularity.Should().Be(TimeSeriesGranularity.Hours);
- config.CreateCollectionOptions.TimeSeriesOptions.TimeField.Should().Be("timestamp");
- }
+ CollectionName = "Logs",
+ BatchSizeLimit = 50,
+ QueueLimit = 100,
+ EagerlyEmitFirstEvent = false,
+ SyncingPeriod = TimeSpan.FromSeconds(4),
+ TimeSeriesGranularity = TimeSeriesGranularity.Hours,
+ LogsExpireAfter = TimeSpan.FromMilliseconds(100)
+ };
+
+ // Assert
+ config.CollectionName.Should().Be("Logs");
+ config.BatchSizeLimit.Should().Be(50);
+ config.QueueLimit.Should().Be(100);
+ config.EagerlyEmitFirstEvent.Should().Be(false);
+ config.SyncingPeriod.Should().Be(TimeSpan.FromSeconds(4));
+ config.TimeSeriesGranularity.Should().Be(TimeSeriesGranularity.Hours);
+ config.LogsExpireAfter.Should().Be(TimeSpan.FromMilliseconds(100));
+
+ config.CreateCollectionOptions.ExpireAfter.Should().Be(TimeSpan.FromMilliseconds(100));
+ config.CreateCollectionOptions.TimeSeriesOptions.Granularity.Should().Be(TimeSeriesGranularity.Hours);
+ config.CreateCollectionOptions.TimeSeriesOptions.TimeField.Should().Be("timestamp");
}
}
\ No newline at end of file
diff --git a/tests/Serilog.Sinks.Mongodb.TimeSeries.Tests/Extensions/LogEventExtensionsTests.cs b/tests/Serilog.Sinks.Mongodb.TimeSeries.Tests/Extensions/LogEventExtensionsTests.cs
index 6cb90a4..88ececa 100644
--- a/tests/Serilog.Sinks.Mongodb.TimeSeries.Tests/Extensions/LogEventExtensionsTests.cs
+++ b/tests/Serilog.Sinks.Mongodb.TimeSeries.Tests/Extensions/LogEventExtensionsTests.cs
@@ -7,41 +7,40 @@
using Serilog.Parsing;
using Serilog.Sinks.Mongodb.TimeSeries.Extensions;
-namespace Serilog.Sinks.Mongodb.TimeSeries.Tests.Extensions
+namespace Serilog.Sinks.Mongodb.TimeSeries.Tests.Extensions;
+
+[TestFixture]
+public class LogEventExtensionsTests
{
- [TestFixture]
- public class LogEventExtensionsTests
+ [Test]
+ public void Should_convert_LogEvents_to_LogDocuments()
{
- [Test]
- public void Should_convert_LogEvents_to_LogDocuments()
+ // Arrange
+ var logsEvents = new List
{
- // Arrange
- var logsEvents = new List
- {
- new (
- new DateTimeOffset(2000, 1, 1, 1, 1, 1, 1, TimeSpan.Zero),
- LogEventLevel.Information,
- null,
- new MessageTemplate(new List
- {
- new TextToken("test message, "),
- new PropertyToken("content", "raw text")
- }),
- new List
- {
- new ("test property", new ScalarValue(1))
- }
- )
- };
-
- // Act
- var docs = logsEvents.ToDocuments().ToList();
-
- // Assert
- docs.Count.Should().Be(logsEvents.Count);
- docs.First().Message.Should().Be("test message, raw text");
- docs.First().Timestamp.Should().Be(new DateTime(2000, 1, 1, 1, 1, 1, 1));
- docs.First().Properties.First().Value.Should().Be(1);
- }
+ new(
+ new DateTimeOffset(2000, 1, 1, 1, 1, 1, 1, TimeSpan.Zero),
+ LogEventLevel.Information,
+ null,
+ new MessageTemplate(new List
+ {
+ new TextToken("test message, "),
+ new PropertyToken("content", "raw text")
+ }),
+ new List
+ {
+ new("test property", new ScalarValue(1))
+ }
+ )
+ };
+
+ // Act
+ var docs = logsEvents.ToDocuments().ToList();
+
+ // Assert
+ docs.Count.Should().Be(logsEvents.Count);
+ docs.First().Message.Should().Be("test message, raw text");
+ docs.First().Timestamp.Should().Be(new DateTime(2000, 1, 1, 1, 1, 1, 1));
+ docs.First().Properties.First().Value.Should().Be(1);
}
}
\ No newline at end of file
diff --git a/tests/Serilog.Sinks.Mongodb.TimeSeries.Tests/Extensions/LogEventLevelExtensionsTests.cs b/tests/Serilog.Sinks.Mongodb.TimeSeries.Tests/Extensions/LogEventLevelExtensionsTests.cs
index df3c1ba..ebf0ad4 100644
--- a/tests/Serilog.Sinks.Mongodb.TimeSeries.Tests/Extensions/LogEventLevelExtensionsTests.cs
+++ b/tests/Serilog.Sinks.Mongodb.TimeSeries.Tests/Extensions/LogEventLevelExtensionsTests.cs
@@ -3,24 +3,23 @@
using Serilog.Events;
using Serilog.Sinks.Mongodb.TimeSeries.Extensions;
-namespace Serilog.Sinks.Mongodb.TimeSeries.Tests.Extensions
+namespace Serilog.Sinks.Mongodb.TimeSeries.Tests.Extensions;
+
+[TestFixture]
+public class LogEventLevelExtensionsTests
{
- [TestFixture]
- public class LogEventLevelExtensionsTests
+ [TestCase(LogEventLevel.Debug, "debug")]
+ [TestCase(LogEventLevel.Verbose, "verbose")]
+ [TestCase(LogEventLevel.Error, "error")]
+ [TestCase(LogEventLevel.Fatal, "fatal")]
+ [TestCase(LogEventLevel.Information, "information")]
+ [TestCase(LogEventLevel.Warning, "warning")]
+ public void ShouldGetSeverityString(LogEventLevel level, string expected)
{
- [TestCase(LogEventLevel.Debug, "debug")]
- [TestCase(LogEventLevel.Verbose, "verbose")]
- [TestCase(LogEventLevel.Error, "error")]
- [TestCase(LogEventLevel.Fatal, "fatal")]
- [TestCase(LogEventLevel.Information, "information")]
- [TestCase(LogEventLevel.Warning, "warning")]
- public void ShouldGetSeverityString(LogEventLevel level, string expected)
- {
- // Act
- var result = level.ToSeverityString();
+ // Act
+ var result = level.ToSeverityString();
- // Assert
- result.Should().Be(expected);
- }
+ // Assert
+ result.Should().Be(expected);
}
}
\ No newline at end of file
diff --git a/tests/Serilog.Sinks.Mongodb.TimeSeries.Tests/Extensions/StringExtensionTests.cs b/tests/Serilog.Sinks.Mongodb.TimeSeries.Tests/Extensions/StringExtensionTests.cs
index 10a0a65..2aa92a4 100644
--- a/tests/Serilog.Sinks.Mongodb.TimeSeries.Tests/Extensions/StringExtensionTests.cs
+++ b/tests/Serilog.Sinks.Mongodb.TimeSeries.Tests/Extensions/StringExtensionTests.cs
@@ -2,21 +2,20 @@
using NUnit.Framework;
using Serilog.Sinks.Mongodb.TimeSeries.Extensions;
-namespace Serilog.Sinks.Mongodb.TimeSeries.Tests.Extensions
+namespace Serilog.Sinks.Mongodb.TimeSeries.Tests.Extensions;
+
+[TestFixture]
+public class StringExtensionTests
{
- [TestFixture]
- public class StringExtensionTests
+ [TestCase(null, "[NULL]")]
+ [TestCase("test.test", "test-test")]
+ [TestCase("$test", "_test")]
+ public void ShouldGetExpectedSavableString(string? value, string expected)
{
- [TestCase(null, "[NULL]")]
- [TestCase("test.test", "test-test")]
- [TestCase("$test", "_test")]
- public void ShouldGetExpectedSavableString(string? value, string expected)
- {
- // Act
- var result = value.ToSaveAbleString();
+ // Act
+ var result = value.ToSaveAbleString();
- // Assert
- result.Should().Be(expected);
- }
+ // Assert
+ result.Should().Be(expected);
}
}
\ No newline at end of file
diff --git a/tests/Serilog.Sinks.Mongodb.TimeSeries.Tests/Serilog.Sinks.Mongodb.TimeSeries.Tests.csproj b/tests/Serilog.Sinks.Mongodb.TimeSeries.Tests/Serilog.Sinks.Mongodb.TimeSeries.Tests.csproj
index 435b17a..3d67040 100644
--- a/tests/Serilog.Sinks.Mongodb.TimeSeries.Tests/Serilog.Sinks.Mongodb.TimeSeries.Tests.csproj
+++ b/tests/Serilog.Sinks.Mongodb.TimeSeries.Tests/Serilog.Sinks.Mongodb.TimeSeries.Tests.csproj
@@ -7,16 +7,16 @@
-
-
-
-
-
-
+
+
+
+
+
+
-
+