diff --git a/serilog-enrichers-memory.sln b/serilog-enrichers-memory.sln
index 726ba78..de88cf7 100644
--- a/serilog-enrichers-memory.sln
+++ b/serilog-enrichers-memory.sln
@@ -1,20 +1,23 @@
Microsoft Visual Studio Solution File, Format Version 12.00
-# Visual Studio 15
-VisualStudioVersion = 15.0.26430.15
+# Visual Studio Version 17
+VisualStudioVersion = 17.10.35013.160
MinimumVisualStudioVersion = 10.0.40219.1
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{037440DE-440B-4129-9F7A-09B42D00397E}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "assets", "assets", "{E9D1B5E1-DEB9-4A04-8BAB-24EC7240ADAF}"
ProjectSection(SolutionItems) = preProject
Build.ps1 = Build.ps1
- NuGet.Config = NuGet.Config
README.md = README.md
assets\SerilogMemory.snk = assets\SerilogMemory.snk
EndProjectSection
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Serilog.Enrichers.Memory", "src\Serilog.Enrichers.Memory\Serilog.Enrichers.Memory.csproj", "{2312A998-5E53-4355-9CB6-6014252B3E88}"
EndProject
+Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "tests", "tests", "{F1A28E03-3590-4F6F-B0D7-7D3008BCDF23}"
+EndProject
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Serilog.Enrichers.Memory.Tests", "tests\Serilog.Enrichers.Memory.Tests\Serilog.Enrichers.Memory.Tests.csproj", "{CC27194E-C8D2-4B1D-ACC5-28F9BDF49546}"
+EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
@@ -25,11 +28,19 @@ Global
{2312A998-5E53-4355-9CB6-6014252B3E88}.Debug|Any CPU.Build.0 = Debug|Any CPU
{2312A998-5E53-4355-9CB6-6014252B3E88}.Release|Any CPU.ActiveCfg = Release|Any CPU
{2312A998-5E53-4355-9CB6-6014252B3E88}.Release|Any CPU.Build.0 = Release|Any CPU
+ {CC27194E-C8D2-4B1D-ACC5-28F9BDF49546}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {CC27194E-C8D2-4B1D-ACC5-28F9BDF49546}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {CC27194E-C8D2-4B1D-ACC5-28F9BDF49546}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {CC27194E-C8D2-4B1D-ACC5-28F9BDF49546}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(NestedProjects) = preSolution
{2312A998-5E53-4355-9CB6-6014252B3E88} = {037440DE-440B-4129-9F7A-09B42D00397E}
+ {CC27194E-C8D2-4B1D-ACC5-28F9BDF49546} = {F1A28E03-3590-4F6F-B0D7-7D3008BCDF23}
+ EndGlobalSection
+ GlobalSection(ExtensibilityGlobals) = postSolution
+ SolutionGuid = {CF4B9AB9-DF05-417C-A8DE-CEBD1695A26B}
EndGlobalSection
EndGlobal
diff --git a/src/Serilog.Enrichers.Memory/Enrichers/MemoryUsageEnricher.cs b/src/Serilog.Enrichers.Memory/Enrichers/MemoryUsageEnricher.cs
index 53598d1..f34eea9 100644
--- a/src/Serilog.Enrichers.Memory/Enrichers/MemoryUsageEnricher.cs
+++ b/src/Serilog.Enrichers.Memory/Enrichers/MemoryUsageEnricher.cs
@@ -1,4 +1,4 @@
-// Copyright 2017 Josh Schreuder
+// Copyright 2017, 2024 Josh Schreuder
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
@@ -16,26 +16,27 @@
using Serilog.Core;
using Serilog.Events;
-namespace Serilog.Enrichers
+// ReSharper disable CheckNamespace
+namespace Serilog.Enrichers;
+// ReSharper restore CheckNamespace
+
+///
+/// Enriches log events with a MemoryUsage property containing an estimation of the current process' memory usage in bytes.
+///
+public class MemoryUsageEnricher : ILogEventEnricher
{
///
- /// Enriches log events with a MemoryUsage property containing an estimation of the current process' memory usage in bytes.
+ /// The property name added to enriched log events.
///
- public class MemoryUsageEnricher : ILogEventEnricher
- {
- ///
- /// The property name added to enriched log events.
- ///
- public const string MemoryUsagePropertyName = "MemoryUsage";
+ public const string MemoryUsagePropertyName = "MemoryUsage";
- ///
- /// Enrich the log event.
- ///
- /// The log event to enrich.
- /// Factory for creating new properties to add to the event.
- public void Enrich(LogEvent logEvent, ILogEventPropertyFactory propertyFactory)
- {
- logEvent.AddPropertyIfAbsent(propertyFactory.CreateProperty(MemoryUsagePropertyName, GC.GetTotalMemory(false)));
- }
+ ///
+ /// Enrich the log event.
+ ///
+ /// The log event to enrich.
+ /// Factory for creating new properties to add to the event.
+ public void Enrich(LogEvent logEvent, ILogEventPropertyFactory propertyFactory)
+ {
+ logEvent.AddPropertyIfAbsent(propertyFactory.CreateProperty(MemoryUsagePropertyName, GC.GetTotalMemory(false)));
}
}
\ No newline at end of file
diff --git a/src/Serilog.Enrichers.Memory/ProcessLoggerConfigurationExtensions.cs b/src/Serilog.Enrichers.Memory/ProcessLoggerConfigurationExtensions.cs
index 73525ee..72b00fd 100644
--- a/src/Serilog.Enrichers.Memory/ProcessLoggerConfigurationExtensions.cs
+++ b/src/Serilog.Enrichers.Memory/ProcessLoggerConfigurationExtensions.cs
@@ -17,24 +17,24 @@
using Serilog.Configuration;
using Serilog.Enrichers;
-namespace Serilog
+// ReSharper disable CheckNamespace
+namespace Serilog;
+// ReSharper restore CheckNamespace
+
+///
+/// Extends to add enrichers related to memory.
+/// capabilities.
+///
+public static class ProcessLoggerConfigurationExtensions
{
///
- /// Extends to add enrichers related to memory.
- /// capabilities.
+ /// Enrich log events with memory usage/>.
///
- public static class ProcessLoggerConfigurationExtensions
- {
- ///
- /// Enrich log events with memory usage/>.
- ///
- /// Logger enrichment configuration.
- /// Configuration object allowing method chaining.
- public static LoggerConfiguration WithMemoryUsage(
- this LoggerEnrichmentConfiguration enrichmentConfiguration)
- {
- if (enrichmentConfiguration == null) throw new ArgumentNullException(nameof(enrichmentConfiguration));
- return enrichmentConfiguration.With();
- }
- }
+ /// Logger enrichment configuration.
+ /// Configuration object allowing method chaining.
+ public static LoggerConfiguration WithMemoryUsage(
+ this LoggerEnrichmentConfiguration enrichmentConfiguration) =>
+ enrichmentConfiguration == null
+ ? throw new ArgumentNullException(nameof(enrichmentConfiguration))
+ : enrichmentConfiguration.With();
}
\ No newline at end of file
diff --git a/src/Serilog.Enrichers.Memory/Serilog.Enrichers.Memory.csproj b/src/Serilog.Enrichers.Memory/Serilog.Enrichers.Memory.csproj
index 0c9ca4c..1191417 100644
--- a/src/Serilog.Enrichers.Memory/Serilog.Enrichers.Memory.csproj
+++ b/src/Serilog.Enrichers.Memory/Serilog.Enrichers.Memory.csproj
@@ -1,10 +1,9 @@
-
The memory enricher for Serilog.
1.0.3
Josh Schreuder
- net45;netstandard1.3;netcoreapp2.0;netstandard2.0
+ net8.0
Serilog.Enrichers.Memory
../../assets/SerilogMemory.snk
true
@@ -15,15 +14,13 @@
https://github.com/JoshSchreuder/serilog-enrichers-memory
http://www.apache.org/licenses/LICENSE-2.0
false
- 1.0.4
+ 1.1.0
-
-
+
-
-
+
\ No newline at end of file
diff --git a/tests/Serilog.Enrichers.Memory.Tests/MemoryUsageEnricherTests.cs b/tests/Serilog.Enrichers.Memory.Tests/MemoryUsageEnricherTests.cs
new file mode 100644
index 0000000..e13cd7b
--- /dev/null
+++ b/tests/Serilog.Enrichers.Memory.Tests/MemoryUsageEnricherTests.cs
@@ -0,0 +1,66 @@
+using System.Diagnostics.CodeAnalysis;
+using Moq;
+using Serilog.Core;
+using Serilog.Events;
+using Serilog.Parsing;
+
+namespace Serilog.Enrichers.Memory.Tests;
+
+[ExcludeFromCodeCoverage]
+public class MemoryUsageEnricherTests
+{
+ [Fact]
+ public void Enrich_ShouldAddMemoryUsageProperty()
+ {
+ // Arrange
+ var enricher = new MemoryUsageEnricher();
+ var logEvent = new LogEvent(DateTimeOffset.Now, LogEventLevel.Information, null, new MessageTemplate(new List()), new List());
+ var propertyFactoryMock = new Mock();
+ propertyFactoryMock.Setup(x => x.CreateProperty(It.IsAny(), It.IsAny