Skip to content

Commit

Permalink
Uses a custom sink to forward Serilog logging messages (#1084)
Browse files Browse the repository at this point in the history
* extend support for Serilog 1.x

* 1. Prevent forwarding duplicate log when Micsoft.Extensions.Logging is used.
2. Fixes an issue where serilog logging supportibity metrics didn't get generated

* - Renames Logging wrapper name to Log4NetLogging.
- Update the msiinstaller solution to include new wrappers.

* Adds a comment around why the serilog wrapper need to be loaded dynamically.
Fixes typos.

* cleans up unused references.
  • Loading branch information
vuqtran88 authored May 16, 2022
1 parent 9f166ac commit add709a
Show file tree
Hide file tree
Showing 13 changed files with 245 additions and 142 deletions.
25 changes: 16 additions & 9 deletions FullAgent.sln
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 16
VisualStudioVersion = 16.0.29613.14
# Visual Studio Version 17
VisualStudioVersion = 17.1.32319.34
MinimumVisualStudioVersion = 15.0.26228.04
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Core", "src\Agent\NewRelic\Agent\Core\Core.csproj", "{D6E22195-EE69-4320-B08B-E68229FB69AB}"
EndProject
Expand Down Expand Up @@ -201,9 +201,11 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Home", "src\Agent\NewRelic\
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CosmosDb", "src\Agent\NewRelic\Agent\Extensions\Providers\Wrapper\CosmosDb\CosmosDb.csproj", "{E10BF2F9-D5CA-4330-8169-ED30D861697E}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Logging", "src\Agent\NewRelic\Agent\Extensions\Providers\Wrapper\Logging\Logging.csproj", "{E696F7DF-D99F-4BD4-B757-531B5F5ECB36}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MicrosoftExtensionsLogging", "src\Agent\NewRelic\Agent\Extensions\Providers\Wrapper\MicrosoftExtensionsLogging\MicrosoftExtensionsLogging.csproj", "{710C7C7A-CD27-4F94-B2D3-9804BD848D57}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MicrosoftExtensionsLogging", "src\Agent\NewRelic\Agent\Extensions\Providers\Wrapper\MicrosoftExtensionsLogging\MicrosoftExtensionsLogging.csproj", "{710C7C7A-CD27-4F94-B2D3-9804BD848D57}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SerilogLogging", "src\Agent\NewRelic\Agent\Extensions\Providers\Wrapper\SerilogLogging\SerilogLogging.csproj", "{0C3E92D7-F16C-4575-9CBB-EB7349A4C5E2}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Log4NetLogging", "src\Agent\NewRelic\Agent\Extensions\Providers\Wrapper\Log4NetLogging\Log4NetLogging.csproj", "{2E6CF650-CB50-453D-830A-D00F0540FC2C}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Expand Down Expand Up @@ -419,14 +421,18 @@ Global
{E10BF2F9-D5CA-4330-8169-ED30D861697E}.Debug|Any CPU.Build.0 = Debug|Any CPU
{E10BF2F9-D5CA-4330-8169-ED30D861697E}.Release|Any CPU.ActiveCfg = Release|Any CPU
{E10BF2F9-D5CA-4330-8169-ED30D861697E}.Release|Any CPU.Build.0 = Release|Any CPU
{E696F7DF-D99F-4BD4-B757-531B5F5ECB36}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{E696F7DF-D99F-4BD4-B757-531B5F5ECB36}.Debug|Any CPU.Build.0 = Debug|Any CPU
{E696F7DF-D99F-4BD4-B757-531B5F5ECB36}.Release|Any CPU.ActiveCfg = Release|Any CPU
{E696F7DF-D99F-4BD4-B757-531B5F5ECB36}.Release|Any CPU.Build.0 = Release|Any CPU
{710C7C7A-CD27-4F94-B2D3-9804BD848D57}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{710C7C7A-CD27-4F94-B2D3-9804BD848D57}.Debug|Any CPU.Build.0 = Debug|Any CPU
{710C7C7A-CD27-4F94-B2D3-9804BD848D57}.Release|Any CPU.ActiveCfg = Release|Any CPU
{710C7C7A-CD27-4F94-B2D3-9804BD848D57}.Release|Any CPU.Build.0 = Release|Any CPU
{0C3E92D7-F16C-4575-9CBB-EB7349A4C5E2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{0C3E92D7-F16C-4575-9CBB-EB7349A4C5E2}.Debug|Any CPU.Build.0 = Debug|Any CPU
{0C3E92D7-F16C-4575-9CBB-EB7349A4C5E2}.Release|Any CPU.ActiveCfg = Release|Any CPU
{0C3E92D7-F16C-4575-9CBB-EB7349A4C5E2}.Release|Any CPU.Build.0 = Release|Any CPU
{2E6CF650-CB50-453D-830A-D00F0540FC2C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{2E6CF650-CB50-453D-830A-D00F0540FC2C}.Debug|Any CPU.Build.0 = Debug|Any CPU
{2E6CF650-CB50-453D-830A-D00F0540FC2C}.Release|Any CPU.ActiveCfg = Release|Any CPU
{2E6CF650-CB50-453D-830A-D00F0540FC2C}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down Expand Up @@ -492,8 +498,9 @@ Global
{E487774C-2805-4642-B173-63D8F2D05D39} = {F617061F-24DF-4C57-8147-84CAB336DD4E}
{5CF47B2E-9370-4FD8-B9BD-0D95D3EA167C} = {E3DAC9C6-AE41-4B37-A253-C621E568590E}
{E10BF2F9-D5CA-4330-8169-ED30D861697E} = {5E86E10A-C38F-48CB-ADE9-67B22BB2F50A}
{E696F7DF-D99F-4BD4-B757-531B5F5ECB36} = {5E86E10A-C38F-48CB-ADE9-67B22BB2F50A}
{710C7C7A-CD27-4F94-B2D3-9804BD848D57} = {5E86E10A-C38F-48CB-ADE9-67B22BB2F50A}
{0C3E92D7-F16C-4575-9CBB-EB7349A4C5E2} = {5E86E10A-C38F-48CB-ADE9-67B22BB2F50A}
{2E6CF650-CB50-453D-830A-D00F0540FC2C} = {5E86E10A-C38F-48CB-ADE9-67B22BB2F50A}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
EnterpriseLibraryConfigurationToolBinariesPath = packages\Unity.2.1.505.2\lib\NET35
Expand Down
28 changes: 20 additions & 8 deletions src/Agent/MsiInstaller/Installer/Product.wxs
Original file line number Diff line number Diff line change
Expand Up @@ -454,8 +454,11 @@ SPDX-License-Identifier: Apache-2.0
<Component Id="AspNetCoreWrapperComponent" Guid="{383038F5-CC7D-4A78-8B10-0F489FEFEBE1}">
<File Id="AspNetCoreWrapperFile" Name="NewRelic.Providers.Wrapper.AspNetCore.dll" KeyPath="yes" Source="$(var.HomeFolderPath)\extensions\NewRelic.Providers.Wrapper.AspNetCore.dll"/>
</Component>
<Component Id="LoggingWrapperComponent" Guid="{E45FB955-F2C4-475E-B057-5C4441381AD2}">
<File Id="LoggingWrapperFile" Name="NewRelic.Providers.Wrapper.Logging.dll" KeyPath="yes" Source="$(var.HomeFolderPath)\extensions\NewRelic.Providers.Wrapper.Logging.dll"/>
<Component Id="Log4NetLoggingWrapperComponent" Guid="{E45FB955-F2C4-475E-B057-5C4441381AD2}">
<File Id="Log4NetLoggingWrapperFile" Name="NewRelic.Providers.Wrapper.Log4NetLogging.dll" KeyPath="yes" Source="$(var.HomeFolderPath)\extensions\NewRelic.Providers.Wrapper.Log4NetLogging.dll"/>
</Component>
<Component Id="SerilogLoggingWrapperComponent" Guid="{6E0C2C78-762F-4022-880A-D5833C265884}">
<File Id="SerilogLoggingWrapperFile" Name="NewRelic.Providers.Wrapper.SerilogLogging.dll" KeyPath="yes" Source="$(var.HomeFolderPath)\extensions\NewRelic.Providers.Wrapper.SerilogLogging.dll"/>
</Component>

<!-- Reference libraries -->
Expand Down Expand Up @@ -492,12 +495,15 @@ SPDX-License-Identifier: Apache-2.0
<Component Id="CoreRabbitMqWrapperComponent" Guid="{758394DD-AB71-4E58-8E18-BF1135F8B2C2}">
<File Id="CoreRabbitMqWrapperFile" Name="NewRelic.Providers.Wrapper.RabbitMq.dll" KeyPath="yes" Source="$(var.HomeFolderPath)_coreclr\extensions\NewRelic.Providers.Wrapper.RabbitMq.dll"/>
</Component>
<Component Id="CoreLoggingWrapperComponent" Guid="{882392E9-9403-41EC-9321-9C6E53781744}">
<File Id="CoreLoggingWrapperFile" Name="NewRelic.Providers.Wrapper.Logging.dll" KeyPath="yes" Source="$(var.HomeFolderPath)_coreclr\extensions\NewRelic.Providers.Wrapper.Logging.dll"/>
<Component Id="CoreLog4NetLoggingWrapperComponent" Guid="{882392E9-9403-41EC-9321-9C6E53781744}">
<File Id="CoreLog4NetLoggingWrapperFile" Name="NewRelic.Providers.Wrapper.Log4NetLogging.dll" KeyPath="yes" Source="$(var.HomeFolderPath)_coreclr\extensions\NewRelic.Providers.Wrapper.Log4NetLogging.dll"/>
</Component>
<Component Id="CoreMicrosoftExtensionsLoggingWrapperComponent" Guid="{247CB27D-7F32-4DE3-965F-505A3A5F75ED}">
<File Id="CoreMicrosoftExtensionsLoggingWrapperFile" Name="NewRelic.Providers.Wrapper.MicrosoftExtensionsLogging.dll" KeyPath="yes" Source="$(var.HomeFolderPath)_coreclr\extensions\NewRelic.Providers.Wrapper.MicrosoftExtensionsLogging.dll"/>
</Component>
<Component Id="CoreSerilogLoggingWrapperComponent" Guid="{9B0099B2-96B8-4491-924E-9B43343B3809}">
<File Id="CoreSerilogLoggingWrapperFile" Name="NewRelic.Providers.Wrapper.SerilogLogging.dll" KeyPath="yes" Source="$(var.HomeFolderPath)_coreclr\extensions\NewRelic.Providers.Wrapper.SerilogLogging.dll"/>
</Component>

<!-- Reference libraries -->
<Component Id="CoreNewRelicCoreReferenceComponent" Guid="{DD2BE979-7D4B-47EA-9FBE-F6B381D70E0B}">
Expand Down Expand Up @@ -585,8 +591,11 @@ SPDX-License-Identifier: Apache-2.0
<Component Id="MiscInstrumentationComponent" Guid="{EE12546C-A328-49A7-84BE-B9A556ADA0A8}">
<File Id="MiscInstrumentationFile" Name="NewRelic.Providers.Wrapper.Misc.Instrumentation.xml" KeyPath="yes" Source="$(var.HomeFolderPath)\extensions\NewRelic.Providers.Wrapper.Misc.Instrumentation.xml"/>
</Component>
<Component Id="LoggingInstrumentationComponent" Guid="{DF1C4FF5-71A3-4C81-912F-0255C6FE231B}">
<File Id="LoggingInstrumentationFile" Name="NewRelic.Providers.Wrapper.Logging.Instrumentation.xml" KeyPath="yes" Source="$(var.HomeFolderPath)\extensions\NewRelic.Providers.Wrapper.Logging.Instrumentation.xml"/>
<Component Id="Log4NetLoggingInstrumentationComponent" Guid="{DF1C4FF5-71A3-4C81-912F-0255C6FE231B}">
<File Id="Log4NetLoggingInstrumentationFile" Name="NewRelic.Providers.Wrapper.Log4NetLogging.Instrumentation.xml" KeyPath="yes" Source="$(var.HomeFolderPath)\extensions\NewRelic.Providers.Wrapper.Log4NetLogging.Instrumentation.xml"/>
</Component>
<Component Id="SerilogLoggingInstrumentationComponent" Guid="{E3E48218-BAC8-428E-8D1A-088D2A5F0637}">
<File Id="SerilogLoggingInstrumentationFile" Name="NewRelic.Providers.Wrapper.SerilogLogging.Instrumentation.xml" KeyPath="yes" Source="$(var.HomeFolderPath)\extensions\NewRelic.Providers.Wrapper.SerilogLogging.Instrumentation.xml"/>
</Component>
</ComponentGroup>

Expand All @@ -612,12 +621,15 @@ SPDX-License-Identifier: Apache-2.0
<Component Id="CoreRabbitMqInstrumentationComponent" Guid="{1CDC18CC-992A-4386-BC4D-DE87A85D9568}">
<File Id="CoreRabbitMqInstrumentationFile" Name="NewRelic.Providers.Wrapper.RabbitMq.Instrumentation.xml" KeyPath="yes" Source="$(var.HomeFolderPath)_coreclr\extensions\NewRelic.Providers.Wrapper.RabbitMq.Instrumentation.xml"/>
</Component>
<Component Id="CoreLoggingInstrumentationComponent" Guid="{A40554DF-870C-477C-8910-1113A221820C}">
<File Id="CoreLoggingInstrumentationFile" Name="NewRelic.Providers.Wrapper.Logging.Instrumentation.xml" KeyPath="yes" Source="$(var.HomeFolderPath)_coreclr\extensions\NewRelic.Providers.Wrapper.Logging.Instrumentation.xml"/>
<Component Id="CoreLog4NetLoggingInstrumentationComponent" Guid="{A40554DF-870C-477C-8910-1113A221820C}">
<File Id="CoreLog4NetLoggingInstrumentationFile" Name="NewRelic.Providers.Wrapper.Log4NetLogging.Instrumentation.xml" KeyPath="yes" Source="$(var.HomeFolderPath)_coreclr\extensions\NewRelic.Providers.Wrapper.Log4NetLogging.Instrumentation.xml"/>
</Component>
<Component Id="CoreMicrosoftExtensionsLoggingInstrumentationComponent" Guid="{133E2C37-4DD7-462F-B0D1-2BD46A6A5970}">
<File Id="CoreMicrosoftExtensionsLoggingInstrumentationFile" Name="NewRelic.Providers.Wrapper.MicrosoftExtensionsLogging.Instrumentation.xml" KeyPath="yes" Source="$(var.HomeFolderPath)_coreclr\extensions\NewRelic.Providers.Wrapper.MicrosoftExtensionsLogging.Instrumentation.xml"/>
</Component>
<Component Id="CoreSerilogLoggingInstrumentationComponent" Guid="{5F7C6A8F-8958-46B1-BC56-5EC197213BC5}">
<File Id="CoreSerilogLoggingInstrumentationFile" Name="NewRelic.Providers.Wrapper.SerilogLogging.Instrumentation.xml" KeyPath="yes" Source="$(var.HomeFolderPath)_coreclr\extensions\NewRelic.Providers.Wrapper.SerilogLogging.Instrumentation.xml"/>
</Component>
</ComponentGroup>

<!-- Extensions XSD-->
Expand Down
4 changes: 4 additions & 0 deletions src/Agent/NewRelic/Agent/Core/Utilities/ExtensionsLoader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,10 @@ public static void Initialize(string installPathExtensionsDirectory)
{ "OpenConnectionTracer", Path.Combine(_installPathExtensionsDirectory, "NewRelic.Providers.Wrapper.Sql.dll") },
{ "OpenConnectionWrapper", Path.Combine(_installPathExtensionsDirectory, "NewRelic.Providers.Wrapper.Sql.dll") },

//The NewRelic.Providers.Wrapper.SerilogLogging.dll depends on the Serilog.dll; therefore, it should
//only be loaded by the agent when Serilog is used otherwise assembly load exception will occur.
{ "SerilogCreateLoggerWrapper", Path.Combine(_installPathExtensionsDirectory, "NewRelic.Providers.Wrapper.SerilogLogging.dll") },
{ "SerilogDispatchWrapper", Path.Combine(_installPathExtensionsDirectory, "NewRelic.Providers.Wrapper.SerilogLogging.dll") }
};

var nonAutoReflectedAssemblies = _dynamicLoadWrapperAssemblies.Values.Distinct().ToList();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
Copyright 2020 New Relic Corporation. All rights reserved.
SPDX-License-Identifier: Apache-2.0
-->
<extension xmlns="urn:newrelic-extension">
<instrumentation>
<tracerFactory name="log4net">
<match assemblyName="log4net" className="log4net.Repository.Hierarchy.Logger">
<exactMethodMatcher methodName="CallAppenders" />
</match>
</tracerFactory>
</instrumentation>
</extension>
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<Project Sdk="Microsoft.NET.Sdk" ToolsVersion="15.0">
<PropertyGroup>
<TargetFrameworks>net45;netstandard2.0</TargetFrameworks>
<RootNamespace>NewRelic.Providers.Wrapper.Logging</RootNamespace>
<AssemblyName>NewRelic.Providers.Wrapper.Logging</AssemblyName>
<Description>Logging Wrapper Provider for New Relic .NET Agent</Description>
<RootNamespace>NewRelic.Providers.Wrapper.Log4NetLogging</RootNamespace>
<AssemblyName>NewRelic.Providers.Wrapper.Log4NetLogging</AssemblyName>
<Description>Log4net Wrapper Provider for New Relic .NET Agent</Description>
</PropertyGroup>
<ItemGroup Condition="'$(TargetFramework)' == 'net45'">
<Reference Include="System" />
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<TargetFramework>netstandard2.0</TargetFramework>
<RootNamespace>NewRelic.Providers.Wrapper.MicrosoftExtensionsLogging</RootNamespace>
<AssemblyName>NewRelic.Providers.Wrapper.MicrosoftExtensionsLogging</AssemblyName>
<Description>Logging Wrapper Provider for New Relic .NET Agent</Description>
<Description>Microsoft.Extensions.Logging Wrapper Provider for New Relic .NET Agent</Description>
</PropertyGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,7 @@ SPDX-License-Identifier: Apache-2.0
-->
<extension xmlns="urn:newrelic-extension">
<instrumentation>

<tracerFactory name="log4net">
<match assemblyName="log4net" className="log4net.Repository.Hierarchy.Logger">
<exactMethodMatcher methodName="CallAppenders" />
</match>
</tracerFactory>

<tracerFactory name="serilog">
<tracerFactory name="SerilogDispatchWrapper">
<!-- For Serilog 1.x -->
<match assemblyName="Serilog" className="Serilog.Core.Pipeline.Logger">
<exactMethodMatcher methodName="Dispatch" />
Expand All @@ -23,6 +16,11 @@ SPDX-License-Identifier: Apache-2.0
<exactMethodMatcher methodName="Dispatch" />
</match>
</tracerFactory>


<tracerFactory name="SerilogCreateLoggerWrapper">
<match assemblyName="Serilog" className="Serilog.LoggerConfiguration">
<exactMethodMatcher methodName="CreateLogger" />
</match>
</tracerFactory>
</instrumentation>
</extension>
Loading

0 comments on commit add709a

Please sign in to comment.