From f3ad0fd3cb36108ab26e6ce4507501b0b525afe1 Mon Sep 17 00:00:00 2001 From: Asafi Yosef Date: Mon, 11 Nov 2019 15:27:23 +0200 Subject: [PATCH 1/2] #96733 add orlens log params to unencrypted tags --- .../Logging/OrleansLogAdapter.cs | 253 +- ....Microdot.Orleans.Hosting.UnitTests.csproj | 2440 +++++++++-------- .../Logging/OrleansLogAdapterTests.cs | 136 + 3 files changed, 1498 insertions(+), 1331 deletions(-) create mode 100644 tests/Gigya.Microdot.Orleans.Hosting.UnitTests/Logging/OrleansLogAdapterTests.cs diff --git a/Gigya.Microdot.Orleans.Hosting/Logging/OrleansLogAdapter.cs b/Gigya.Microdot.Orleans.Hosting/Logging/OrleansLogAdapter.cs index 3e7b1b25..c3c907f2 100644 --- a/Gigya.Microdot.Orleans.Hosting/Logging/OrleansLogAdapter.cs +++ b/Gigya.Microdot.Orleans.Hosting/Logging/OrleansLogAdapter.cs @@ -1,113 +1,142 @@ -#region Copyright -// Copyright 2017 Gigya Inc. All rights reserved. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER AND CONTRIBUTORS "AS IS" -// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE -// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE -// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR -// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF -// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS -// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN -// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) -// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE -// POSSIBILITY OF SUCH DAMAGE. -#endregion - -using System; -using System.Diagnostics; -using Gigya.Microdot.Interfaces.Logging; -using Microsoft.Extensions.Logging; -using Microsoft.Extensions.Logging.Abstractions.Internal; - -namespace Gigya.Microdot.Orleans.Hosting.Logging -{ - public class OrleansLogAdapter : ILogger - { - private readonly OrleansLogEnrichment _logEnrichment; - private readonly ILog _logImplementation; - private readonly Func _orleansConfigFunc; - private readonly string _categoryUnderline; - - public OrleansLogAdapter(string category, Func logImplementation, OrleansLogEnrichment logEnrichment, Func orleansConfigFunc) - { - _categoryUnderline = category?.Replace(".", "_"); // The element in config, contains '_' for every '.' in class name - _logEnrichment = logEnrichment; - _orleansConfigFunc = orleansConfigFunc; - _logImplementation = logImplementation(category); - } - - public void Log(LogLevel logLevel, EventId eventId, TState state, Exception exception, Func formatter) - { - string eventHeuristicName = null; - if (eventId.Name == null) - { - _logEnrichment.HeuristicEventIdToName.TryGetValue(eventId.Id, out eventHeuristicName); - } - - var logMessage = formatter(state, exception); - - Action action = _ => _(logMessage, exception: exception, unencryptedTags: new { eventId.Id, eventId.Name, IsOrleansLog = true, eventHeuristicName }); - var level = TraceEventType.Critical; - switch (logLevel) - { - case LogLevel.Trace: - level = TraceEventType.Verbose; - break; - case LogLevel.Debug: - level = TraceEventType.Verbose; - break; - case LogLevel.Information: - level = TraceEventType.Information; - break; - case LogLevel.Warning: - level = TraceEventType.Warning; - break; - case LogLevel.Error: - level = TraceEventType.Error; - break; - case LogLevel.Critical: - level = TraceEventType.Critical; - break; - case LogLevel.None: - return; - } - _logImplementation.Write(level, action); - - } - - public bool IsEnabled(LogLevel logLevel) - { - // #ORLEANS2 [Done] We paid attention to massive GC when deactivation of huge amount of grains - // as orleans code concatenates grain ids for the log entry - // see more details in https://github.com/dotnet/orleans/issues/5851 - - var config = _orleansConfigFunc(); - - // Configure the log level according to the category. - if(_categoryUnderline != null && config.CategoryLogLevels.Count >0) - if (config.CategoryLogLevels.TryGetValue(_categoryUnderline, out var configLogLevel)) - { - return logLevel >= configLogLevel.LogLevel; - } - - return logLevel >= config.DefaultCategoryLogLevel; - } - - public IDisposable BeginScope(TState state) - { - return NullScope.Instance; - } - - public void Write(TraceEventType level, Action log, string file = "", int line = 0, string method = null) - { - _logImplementation.Write(level, log, file, line, method); - } - } +#region Copyright +// Copyright 2017 Gigya Inc. All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER AND CONTRIBUTORS "AS IS" +// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE +// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +// POSSIBILITY OF SUCH DAMAGE. +#endregion + +using System; +using System.Collections.Generic; +using System.Diagnostics; +using System.Dynamic; +using System.Linq; +using Gigya.Microdot.Interfaces.Logging; +using Microsoft.Extensions.Logging; +using Microsoft.Extensions.Logging.Abstractions.Internal; +using Microsoft.Extensions.Logging.Internal; + +namespace Gigya.Microdot.Orleans.Hosting.Logging +{ + public class OrleansLogAdapter : ILogger + { + private readonly string[] _logKeysToIgnore = { "{OriginalFormat}" }; + private readonly OrleansLogEnrichment _logEnrichment; + private readonly ILog _logImplementation; + private readonly Func _orleansConfigFunc; + private readonly string _categoryUnderline; + + public OrleansLogAdapter(string category, Func logImplementation, OrleansLogEnrichment logEnrichment, Func orleansConfigFunc) + { + _categoryUnderline = category?.Replace(".", "_"); // The element in config, contains '_' for every '.' in class name + _logEnrichment = logEnrichment; + _orleansConfigFunc = orleansConfigFunc; + _logImplementation = logImplementation(category); + } + + public void Log(LogLevel logLevel, EventId eventId, TState state, Exception exception, Func formatter) + { + string eventHeuristicName = null; + if (eventId.Name == null) + { + _logEnrichment.HeuristicEventIdToName.TryGetValue(eventId.Id, out eventHeuristicName); + } + + var logMessage = formatter(state, exception); + + var unencryptedTags = new Dictionary + { + {"eventId.Id", eventId.Id}, + {"eventId.Name", eventId.Name}, + {"IsOrleansLog", true}, + {"eventHeuristicName", eventHeuristicName} + }; + + if (state is FormattedLogValues values) + { + foreach (var value in values) + { + if (!_logKeysToIgnore.Contains(value.Key)) + { + unencryptedTags[value.Key] = value.Value; + } + } + } + + var level = TraceEventType.Critical; + switch (logLevel) + { + case LogLevel.Trace: + level = TraceEventType.Verbose; + break; + case LogLevel.Debug: + level = TraceEventType.Verbose; + break; + case LogLevel.Information: + level = TraceEventType.Information; + break; + case LogLevel.Warning: + level = TraceEventType.Warning; + break; + case LogLevel.Error: + level = TraceEventType.Error; + break; + case LogLevel.Critical: + level = TraceEventType.Critical; + break; + case LogLevel.None: + return; + } + _logImplementation.Write(level, LogDelegateAction); + + void LogDelegateAction(LogDelegate logDelegate) + { + logDelegate(logMessage, exception: exception, unencryptedTags: unencryptedTags); + } + + } + + + public bool IsEnabled(LogLevel logLevel) + { + // #ORLEANS2 [Done] We paid attention to massive GC when deactivation of huge amount of grains + // as orleans code concatenates grain ids for the log entry + // see more details in https://github.com/dotnet/orleans/issues/5851 + + var config = _orleansConfigFunc(); + + // Configure the log level according to the category. + if(_categoryUnderline != null && config.CategoryLogLevels.Count >0) + if (config.CategoryLogLevels.TryGetValue(_categoryUnderline, out var configLogLevel)) + { + return logLevel >= configLogLevel.LogLevel; + } + + return logLevel >= config.DefaultCategoryLogLevel; + } + + public IDisposable BeginScope(TState state) + { + return NullScope.Instance; + } + + public void Write(TraceEventType level, Action log, string file = "", int line = 0, string method = null) + { + _logImplementation.Write(level, log, file, line, method); + } + } } \ No newline at end of file diff --git a/tests/Gigya.Microdot.Orleans.Hosting.UnitTests/Gigya.Microdot.Orleans.Hosting.UnitTests.csproj b/tests/Gigya.Microdot.Orleans.Hosting.UnitTests/Gigya.Microdot.Orleans.Hosting.UnitTests.csproj index dfac5c40..acc5d5c0 100644 --- a/tests/Gigya.Microdot.Orleans.Hosting.UnitTests/Gigya.Microdot.Orleans.Hosting.UnitTests.csproj +++ b/tests/Gigya.Microdot.Orleans.Hosting.UnitTests/Gigya.Microdot.Orleans.Hosting.UnitTests.csproj @@ -1,1226 +1,1228 @@ - - - - - - - Debug - AnyCPU - {8E548D57-5880-4283-BDF5-7386886D481D} - Library - Properties - Gigya.Microdot.Orleans.Hosting.UnitTests - Gigya.Microdot.Orleans.Hosting.UnitTests - v4.7.2 - 512 - - true - true - 1591 - - - true - full - false - bin\Debug\ - DEBUG;TRACE - prompt - 3 - CS1998 - - - pdbonly - true - bin\Release\ - TRACE - prompt - 4 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Designer - - - PreserveNewest - - - - + + + + + + + Debug + AnyCPU + {8E548D57-5880-4283-BDF5-7386886D481D} + Library + Properties + Gigya.Microdot.Orleans.Hosting.UnitTests + Gigya.Microdot.Orleans.Hosting.UnitTests + v4.7.2 + 512 + + true + true + 1591 + + + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 3 + CS1998 + + + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Designer + + + PreserveNewest + + + + - - - {47CBF637-AB8F-4568-86D6-EAB6EF08B9CE} - Gigya.Microdot.Common.Tests - - - {0E3A2422-DD99-4D75-A18C-96329A842742} - Gigya.Microdot.Configuration - - - {33C1B76E-47B2-40BC-A434-81EE22996BEF} - Gigya.Microdot.Hosting - - - {2865F69B-D847-4901-8945-4941E463F94E} - Gigya.Microdot.Fakes - - - {63E40F38-DF99-4DF5-9B45-ADDB0C2FC9FF} - Gigya.Microdot.Ninject - - - {AE847E21-F7D8-47FB-84C3-C7144A9B7A1D} - Gigya.Microdot.Orleans.Ninject.Host - - - {37e6909e-51e2-4bba-8efc-dbdf086d860e} - Gigya.Microdot.ServiceDiscovery - - - {1FCB2569-A640-4292-9CDC-821AEEF14813} - Gigya.Microdot.ServiceProxy - - - {C88DB2A8-A1D2-46F8-8B65-06B9EE3F1662} - Gigya.Microdot.SharedLogic - - - {A90D7C71-EC7C-4328-9DB1-D2C3A30727DB} - Gigya.Microdot.Interfaces - - - {DD807780-01B0-4EF6-9E42-5D15CA26F353} - Gigya.Microdot.Orleans.Hosting - - - {d37e359c-170e-4d67-ad49-45002b48987e} - Gigya.Microdot.Testing - - - {6D6A62A1-15B5-44C2-AD37-698AB31863E4} - Gigya.Microdot.Testing.Shared - - - - - - - - - - True - - - ..\..\packages\Castle.Core\lib\net45\Castle.Core.dll - True - True - - - - - - - - - ..\..\packages\Gigya.ServiceContract\lib\net451\Gigya.ServiceContract.dll - True - True - - - - - - - - - ..\..\packages\Microsoft.AspNetCore.Connections.Abstractions\lib\netstandard2.0\Microsoft.AspNetCore.Connections.Abstractions.dll - True - True - - - - - - - - - ..\..\packages\Microsoft.AspNetCore.Hosting\lib\netstandard2.0\Microsoft.AspNetCore.Hosting.dll - True - True - - - - - - - - - ..\..\packages\Microsoft.AspNetCore.Hosting.Abstractions\lib\netstandard2.0\Microsoft.AspNetCore.Hosting.Abstractions.dll - True - True - - - - - - - - - ..\..\packages\Microsoft.AspNetCore.Hosting.Server.Abstractions\lib\netstandard2.0\Microsoft.AspNetCore.Hosting.Server.Abstractions.dll - True - True - - - - - - - - - ..\..\packages\Microsoft.AspNetCore.Http\lib\netstandard2.0\Microsoft.AspNetCore.Http.dll - True - True - - - - - - - - - ..\..\packages\Microsoft.AspNetCore.Http.Abstractions\lib\netstandard2.0\Microsoft.AspNetCore.Http.Abstractions.dll - True - True - - - - - - - - - ..\..\packages\Microsoft.AspNetCore.Http.Extensions\lib\netstandard2.0\Microsoft.AspNetCore.Http.Extensions.dll - True - True - - - - - - - - - ..\..\packages\Microsoft.AspNetCore.Http.Features\lib\netstandard2.0\Microsoft.AspNetCore.Http.Features.dll - True - True - - - - - - - - - ..\..\packages\Microsoft.AspNetCore.Server.Kestrel\lib\netstandard2.0\Microsoft.AspNetCore.Server.Kestrel.dll - True - True - - - - - - - - - ..\..\packages\Microsoft.AspNetCore.Server.Kestrel.Core\lib\netstandard2.0\Microsoft.AspNetCore.Server.Kestrel.Core.dll - True - True - - - - - - - - - ..\..\packages\Microsoft.AspNetCore.Server.Kestrel.Https\lib\netstandard2.0\Microsoft.AspNetCore.Server.Kestrel.Https.dll - True - True - - - - - - - - - ..\..\packages\Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions\lib\netstandard2.0\Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions.dll - True - True - - - - - - - - - ..\..\packages\Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets\lib\netstandard2.0\Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets.dll - True - True - - - - - - - - - ..\..\packages\Microsoft.AspNetCore.WebUtilities\lib\netstandard2.0\Microsoft.AspNetCore.WebUtilities.dll - True - True - - - - - - - True - - - True - - - True - - - True - - - True - - - True - - - True - - - True - - - True - - - True - - - True - - - True - - - True - - - True - - - True - - - True - - - True - - - True - - - True - - - True - - - True - - - True - - - True - - - True - - - True - - - True - - - True - - - True - - - - - - - ..\..\packages\Microsoft.CodeAnalysis.Common\lib\netstandard2.0\Microsoft.CodeAnalysis.dll - True - True - - - - - - - - - ..\..\packages\Microsoft.CodeAnalysis.CSharp\lib\netstandard2.0\Microsoft.CodeAnalysis.CSharp.dll - True - True - - - - - - - - - ..\..\packages\Microsoft.DotNet.PlatformAbstractions\lib\net45\Microsoft.DotNet.PlatformAbstractions.dll - True - True - - - - - - - - - ..\..\packages\Microsoft.Extensions.Configuration\lib\netstandard2.0\Microsoft.Extensions.Configuration.dll - True - True - - - - - - - - - ..\..\packages\Microsoft.Extensions.Configuration.Abstractions\lib\netstandard2.0\Microsoft.Extensions.Configuration.Abstractions.dll - True - True - - - - - - - - - ..\..\packages\Microsoft.Extensions.Configuration.Binder\lib\netstandard2.0\Microsoft.Extensions.Configuration.Binder.dll - True - True - - - - - - - - - ..\..\packages\Microsoft.Extensions.Configuration.EnvironmentVariables\lib\netstandard2.0\Microsoft.Extensions.Configuration.EnvironmentVariables.dll - True - True - - - - - - - - - ..\..\packages\Microsoft.Extensions.Configuration.FileExtensions\lib\netstandard2.0\Microsoft.Extensions.Configuration.FileExtensions.dll - True - True - - - - - - - - - ..\..\packages\Microsoft.Extensions.DependencyInjection\lib\net461\Microsoft.Extensions.DependencyInjection.dll - True - True - - - - - - - - - ..\..\packages\Microsoft.Extensions.DependencyInjection.Abstractions\lib\netstandard2.0\Microsoft.Extensions.DependencyInjection.Abstractions.dll - True - True - - - - - - - - - ..\..\packages\Microsoft.Extensions.DependencyModel\lib\net451\Microsoft.Extensions.DependencyModel.dll - True - True - - - - - - - - - ..\..\packages\Microsoft.Extensions.FileProviders.Abstractions\lib\netstandard2.0\Microsoft.Extensions.FileProviders.Abstractions.dll - True - True - - - - - - - - - ..\..\packages\Microsoft.Extensions.FileProviders.Physical\lib\netstandard2.0\Microsoft.Extensions.FileProviders.Physical.dll - True - True - - - - - - - - - ..\..\packages\Microsoft.Extensions.FileSystemGlobbing\lib\netstandard2.0\Microsoft.Extensions.FileSystemGlobbing.dll - True - True - - - - - - - - - ..\..\packages\Microsoft.Extensions.Hosting.Abstractions\lib\netstandard2.0\Microsoft.Extensions.Hosting.Abstractions.dll - True - True - - - - - - - - - ..\..\packages\Microsoft.Extensions.Logging\lib\netstandard2.0\Microsoft.Extensions.Logging.dll - True - True - - - - - - - - - ..\..\packages\Microsoft.Extensions.Logging.Abstractions\lib\netstandard2.0\Microsoft.Extensions.Logging.Abstractions.dll - True - True - - - - - - - - - ..\..\packages\Microsoft.Extensions.ObjectPool\lib\netstandard2.0\Microsoft.Extensions.ObjectPool.dll - True - True - - - - - - - - - ..\..\packages\Microsoft.Extensions.Options\lib\netstandard2.0\Microsoft.Extensions.Options.dll - True - True - - - - - - - - - ..\..\packages\Microsoft.Extensions.Options.ConfigurationExtensions\lib\netstandard2.0\Microsoft.Extensions.Options.ConfigurationExtensions.dll - True - True - - - - - - - - - ..\..\packages\Microsoft.Extensions.Primitives\lib\netstandard2.0\Microsoft.Extensions.Primitives.dll - True - True - - - - - - - - - ..\..\packages\Microsoft.Net.Http.Headers\lib\netstandard2.0\Microsoft.Net.Http.Headers.dll - True - True - - - - - - - - - ..\..\packages\Microsoft.Orleans.Core\lib\netstandard2.0\Orleans.Core.dll - True - True - - - - - - - - - ..\..\packages\Microsoft.Orleans.Core.Abstractions\lib\netstandard2.0\Orleans.Core.Abstractions.dll - True - True - - - - - - - - - ..\..\packages\Microsoft.Orleans.OrleansCodeGenerator\lib\netstandard2.0\Orleans.CodeGeneration.dll - True - True - - - - - - - - - ..\..\packages\Microsoft.Orleans.OrleansProviders\lib\netstandard2.0\OrleansProviders.dll - True - True - - - - - - - - - ..\..\packages\Microsoft.Orleans.Runtime.Abstractions\lib\netstandard2.0\Orleans.Runtime.Abstractions.dll - True - True - - - - - - - - - ..\..\packages\Newtonsoft.Json\lib\net45\Newtonsoft.Json.dll - True - True - - - - - - - - - ..\..\packages\Ninject\lib\net45\Ninject.dll - True - True - - - - - - - - - ..\..\packages\NSubstitute\lib\net46\NSubstitute.dll - True - True - - - - - - - - - ..\..\packages\NUnit\lib\net45\nunit.framework.dll - True - True - - - - - - - - - ..\..\packages\Shouldly\lib\net451\Shouldly.dll - True - True - - - - - - - - - ..\..\packages\System.Buffers\lib\netstandard2.0\System.Buffers.dll - True - True - - - - - - - - - ..\..\packages\System.Collections.Immutable\lib\netstandard2.0\System.Collections.Immutable.dll - True - True - - - - - - - - - True - - - ..\..\packages\System.Collections.NonGeneric\lib\net46\System.Collections.NonGeneric.dll - False - True - - - - - - - - - True - - - ..\..\packages\System.ComponentModel.Annotations\lib\net461\System.ComponentModel.Annotations.dll - True - True - - - - - - - - - ..\..\packages\System.ComponentModel.Primitives\lib\net45\System.ComponentModel.Primitives.dll - False - True - - - - - - - - - ..\..\packages\System.ComponentModel.TypeConverter\lib\net462\System.ComponentModel.TypeConverter.dll - False - True - - - - - - - - - ..\..\packages\System.Diagnostics.DiagnosticSource\lib\net46\System.Diagnostics.DiagnosticSource.dll - True - True - - - - - - - - - ..\..\packages\System.Diagnostics.FileVersionInfo\lib\net46\System.Diagnostics.FileVersionInfo.dll - False - True - - - - - - - - - ..\..\packages\System.Diagnostics.Process\lib\net461\System.Diagnostics.Process.dll - False - True - - - - - - - - - ..\..\packages\System.Diagnostics.TraceSource\lib\net46\System.Diagnostics.TraceSource.dll - False - True - - - - - - - - - ..\..\packages\System.IO\lib\net462\System.IO.dll - False - True - - - - - - - - - ..\..\packages\System.IO.Pipelines\lib\netstandard2.0\System.IO.Pipelines.dll - True - True - - - - - - - - - ..\..\packages\System.Linq.Expressions\lib\net463\System.Linq.Expressions.dll - False - True - - - - - - - - - ..\..\packages\System.Memory\lib\netstandard2.0\System.Memory.dll - True - True - - - - - - - - - ..\..\packages\System.Net.NameResolution\lib\net46\System.Net.NameResolution.dll - False - True - - - - - - - - - ..\..\packages\System.Net.NetworkInformation\lib\net46\System.Net.NetworkInformation.dll - False - True - - - - - - - - - True - - - ..\..\packages\System.Numerics.Vectors\lib\net46\System.Numerics.Vectors.dll - True - True - - - - - - - - - ..\..\packages\System.Reflection\lib\net462\System.Reflection.dll - False - True - - - - - - - - - ..\..\packages\System.Reflection.Metadata\lib\netstandard2.0\System.Reflection.Metadata.dll - True - True - - - - - - - - - ..\..\packages\System.Reflection.TypeExtensions\lib\net461\System.Reflection.TypeExtensions.dll - True - True - - - - - - - - - True - - - ..\..\packages\System.Runtime\lib\net462\System.Runtime.dll - False - True - - - - - - - - - ..\..\packages\System.Runtime.CompilerServices.Unsafe\lib\netstandard2.0\System.Runtime.CompilerServices.Unsafe.dll - True - True - - - - - - - - - ..\..\packages\System.Runtime.InteropServices.RuntimeInformation\lib\net45\System.Runtime.InteropServices.RuntimeInformation.dll - False - True - - - - - - - - - ..\..\packages\System.Runtime.Serialization.Formatters\lib\net46\System.Runtime.Serialization.Formatters.dll - False - True - - - - - - - - - True - - - ..\..\packages\System.Runtime.Serialization.Primitives\lib\net46\System.Runtime.Serialization.Primitives.dll - False - True - - - - - - - - - ..\..\packages\System.Security.Cryptography.Algorithms\lib\net463\System.Security.Cryptography.Algorithms.dll - False - True - - - - - - - - - ..\..\packages\System.Security.Cryptography.Cng\lib\net47\System.Security.Cryptography.Cng.dll - True - True - - - - - - - - - ..\..\packages\System.Security.Cryptography.Encoding\lib\net46\System.Security.Cryptography.Encoding.dll - False - True - - - - - - - - - ..\..\packages\System.Security.Cryptography.Primitives\lib\net46\System.Security.Cryptography.Primitives.dll - False - True - - - - - - - - - ..\..\packages\System.Text.Encoding.CodePages\lib\net461\System.Text.Encoding.CodePages.dll - True - True - - - - - - - - - ..\..\packages\System.Text.Encodings.Web\lib\netstandard2.0\System.Text.Encodings.Web.dll - True - True - - - - - - - - - ..\..\packages\System.Threading.Tasks.Dataflow\lib\netstandard2.0\System.Threading.Tasks.Dataflow.dll - True - True - - - - - - - - - ..\..\packages\System.Threading.Tasks.Extensions\lib\netstandard2.0\System.Threading.Tasks.Extensions.dll - True - True - - - - - - - - - ..\..\packages\System.Threading.Thread\lib\net46\System.Threading.Thread.dll - False - True - - - - - - - - - ..\..\packages\System.Threading.ThreadPool\lib\net46\System.Threading.ThreadPool.dll - False - True - - - - - - - - - ..\..\packages\System.ValueTuple\lib\net47\System.ValueTuple.dll - True - True - - - - - - - - - ..\..\packages\System.Xml.XmlDocument\lib\net46\System.Xml.XmlDocument.dll - False - True - - - - - - - - - ..\..\packages\System.Xml.XPath\lib\net46\System.Xml.XPath.dll - False - True - - - - - - - - - ..\..\packages\System.Xml.XPath.XmlDocument\lib\net46\System.Xml.XPath.XmlDocument.dll - True - True - - - - - - - - - ..\..\packages\ZooKeeperNetEx\lib\net461\ZooKeeperNetEx.dll - True - True - - - - - + --> + + + {47CBF637-AB8F-4568-86D6-EAB6EF08B9CE} + Gigya.Microdot.Common.Tests + + + {0E3A2422-DD99-4D75-A18C-96329A842742} + Gigya.Microdot.Configuration + + + {33C1B76E-47B2-40BC-A434-81EE22996BEF} + Gigya.Microdot.Hosting + + + {2865F69B-D847-4901-8945-4941E463F94E} + Gigya.Microdot.Fakes + + + {63E40F38-DF99-4DF5-9B45-ADDB0C2FC9FF} + Gigya.Microdot.Ninject + + + {AE847E21-F7D8-47FB-84C3-C7144A9B7A1D} + Gigya.Microdot.Orleans.Ninject.Host + + + {37e6909e-51e2-4bba-8efc-dbdf086d860e} + Gigya.Microdot.ServiceDiscovery + + + {1FCB2569-A640-4292-9CDC-821AEEF14813} + Gigya.Microdot.ServiceProxy + + + {C88DB2A8-A1D2-46F8-8B65-06B9EE3F1662} + Gigya.Microdot.SharedLogic + + + {A90D7C71-EC7C-4328-9DB1-D2C3A30727DB} + Gigya.Microdot.Interfaces + + + {DD807780-01B0-4EF6-9E42-5D15CA26F353} + Gigya.Microdot.Orleans.Hosting + + + {d37e359c-170e-4d67-ad49-45002b48987e} + Gigya.Microdot.Testing + + + {6D6A62A1-15B5-44C2-AD37-698AB31863E4} + Gigya.Microdot.Testing.Shared + + + + + + + + + + True + + + ..\..\packages\Castle.Core\lib\net45\Castle.Core.dll + True + True + + + + + + + + + ..\..\packages\Gigya.ServiceContract\lib\net451\Gigya.ServiceContract.dll + True + True + + + + + + + + + ..\..\packages\Microsoft.AspNetCore.Connections.Abstractions\lib\netstandard2.0\Microsoft.AspNetCore.Connections.Abstractions.dll + True + True + + + + + + + + + ..\..\packages\Microsoft.AspNetCore.Hosting\lib\netstandard2.0\Microsoft.AspNetCore.Hosting.dll + True + True + + + + + + + + + ..\..\packages\Microsoft.AspNetCore.Hosting.Abstractions\lib\netstandard2.0\Microsoft.AspNetCore.Hosting.Abstractions.dll + True + True + + + + + + + + + ..\..\packages\Microsoft.AspNetCore.Hosting.Server.Abstractions\lib\netstandard2.0\Microsoft.AspNetCore.Hosting.Server.Abstractions.dll + True + True + + + + + + + + + ..\..\packages\Microsoft.AspNetCore.Http\lib\netstandard2.0\Microsoft.AspNetCore.Http.dll + True + True + + + + + + + + + ..\..\packages\Microsoft.AspNetCore.Http.Abstractions\lib\netstandard2.0\Microsoft.AspNetCore.Http.Abstractions.dll + True + True + + + + + + + + + ..\..\packages\Microsoft.AspNetCore.Http.Extensions\lib\netstandard2.0\Microsoft.AspNetCore.Http.Extensions.dll + True + True + + + + + + + + + ..\..\packages\Microsoft.AspNetCore.Http.Features\lib\netstandard2.0\Microsoft.AspNetCore.Http.Features.dll + True + True + + + + + + + + + ..\..\packages\Microsoft.AspNetCore.Server.Kestrel\lib\netstandard2.0\Microsoft.AspNetCore.Server.Kestrel.dll + True + True + + + + + + + + + ..\..\packages\Microsoft.AspNetCore.Server.Kestrel.Core\lib\netstandard2.0\Microsoft.AspNetCore.Server.Kestrel.Core.dll + True + True + + + + + + + + + ..\..\packages\Microsoft.AspNetCore.Server.Kestrel.Https\lib\netstandard2.0\Microsoft.AspNetCore.Server.Kestrel.Https.dll + True + True + + + + + + + + + ..\..\packages\Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions\lib\netstandard2.0\Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions.dll + True + True + + + + + + + + + ..\..\packages\Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets\lib\netstandard2.0\Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets.dll + True + True + + + + + + + + + ..\..\packages\Microsoft.AspNetCore.WebUtilities\lib\netstandard2.0\Microsoft.AspNetCore.WebUtilities.dll + True + True + + + + + + + True + + + True + + + True + + + True + + + True + + + True + + + True + + + True + + + True + + + True + + + True + + + True + + + True + + + True + + + True + + + True + + + True + + + True + + + True + + + True + + + True + + + True + + + True + + + True + + + True + + + True + + + True + + + True + + + + + + + + ..\..\packages\Microsoft.CodeAnalysis.Common\lib\netstandard2.0\Microsoft.CodeAnalysis.dll + True + True + + + + + + + + + ..\..\packages\Microsoft.CodeAnalysis.CSharp\lib\netstandard2.0\Microsoft.CodeAnalysis.CSharp.dll + True + True + + + + + + + + + ..\..\packages\Microsoft.DotNet.PlatformAbstractions\lib\net45\Microsoft.DotNet.PlatformAbstractions.dll + True + True + + + + + + + + + ..\..\packages\Microsoft.Extensions.Configuration\lib\netstandard2.0\Microsoft.Extensions.Configuration.dll + True + True + + + + + + + + + ..\..\packages\Microsoft.Extensions.Configuration.Abstractions\lib\netstandard2.0\Microsoft.Extensions.Configuration.Abstractions.dll + True + True + + + + + + + + + ..\..\packages\Microsoft.Extensions.Configuration.Binder\lib\netstandard2.0\Microsoft.Extensions.Configuration.Binder.dll + True + True + + + + + + + + + ..\..\packages\Microsoft.Extensions.Configuration.EnvironmentVariables\lib\netstandard2.0\Microsoft.Extensions.Configuration.EnvironmentVariables.dll + True + True + + + + + + + + + ..\..\packages\Microsoft.Extensions.Configuration.FileExtensions\lib\netstandard2.0\Microsoft.Extensions.Configuration.FileExtensions.dll + True + True + + + + + + + + + ..\..\packages\Microsoft.Extensions.DependencyInjection\lib\net461\Microsoft.Extensions.DependencyInjection.dll + True + True + + + + + + + + + ..\..\packages\Microsoft.Extensions.DependencyInjection.Abstractions\lib\netstandard2.0\Microsoft.Extensions.DependencyInjection.Abstractions.dll + True + True + + + + + + + + + ..\..\packages\Microsoft.Extensions.DependencyModel\lib\net451\Microsoft.Extensions.DependencyModel.dll + True + True + + + + + + + + + ..\..\packages\Microsoft.Extensions.FileProviders.Abstractions\lib\netstandard2.0\Microsoft.Extensions.FileProviders.Abstractions.dll + True + True + + + + + + + + + ..\..\packages\Microsoft.Extensions.FileProviders.Physical\lib\netstandard2.0\Microsoft.Extensions.FileProviders.Physical.dll + True + True + + + + + + + + + ..\..\packages\Microsoft.Extensions.FileSystemGlobbing\lib\netstandard2.0\Microsoft.Extensions.FileSystemGlobbing.dll + True + True + + + + + + + + + ..\..\packages\Microsoft.Extensions.Hosting.Abstractions\lib\netstandard2.0\Microsoft.Extensions.Hosting.Abstractions.dll + True + True + + + + + + + + + ..\..\packages\Microsoft.Extensions.Logging\lib\netstandard2.0\Microsoft.Extensions.Logging.dll + True + True + + + + + + + + + ..\..\packages\Microsoft.Extensions.Logging.Abstractions\lib\netstandard2.0\Microsoft.Extensions.Logging.Abstractions.dll + True + True + + + + + + + + + ..\..\packages\Microsoft.Extensions.ObjectPool\lib\netstandard2.0\Microsoft.Extensions.ObjectPool.dll + True + True + + + + + + + + + ..\..\packages\Microsoft.Extensions.Options\lib\netstandard2.0\Microsoft.Extensions.Options.dll + True + True + + + + + + + + + ..\..\packages\Microsoft.Extensions.Options.ConfigurationExtensions\lib\netstandard2.0\Microsoft.Extensions.Options.ConfigurationExtensions.dll + True + True + + + + + + + + + ..\..\packages\Microsoft.Extensions.Primitives\lib\netstandard2.0\Microsoft.Extensions.Primitives.dll + True + True + + + + + + + + + ..\..\packages\Microsoft.Net.Http.Headers\lib\netstandard2.0\Microsoft.Net.Http.Headers.dll + True + True + + + + + + + + + ..\..\packages\Microsoft.Orleans.Core\lib\netstandard2.0\Orleans.Core.dll + True + True + + + + + + + + + ..\..\packages\Microsoft.Orleans.Core.Abstractions\lib\netstandard2.0\Orleans.Core.Abstractions.dll + True + True + + + + + + + + + ..\..\packages\Microsoft.Orleans.OrleansCodeGenerator\lib\netstandard2.0\Orleans.CodeGeneration.dll + True + True + + + + + + + + + ..\..\packages\Microsoft.Orleans.OrleansProviders\lib\netstandard2.0\OrleansProviders.dll + True + True + + + + + + + + + ..\..\packages\Microsoft.Orleans.Runtime.Abstractions\lib\netstandard2.0\Orleans.Runtime.Abstractions.dll + True + True + + + + + + + + + ..\..\packages\Newtonsoft.Json\lib\net45\Newtonsoft.Json.dll + True + True + + + + + + + + + ..\..\packages\Ninject\lib\net45\Ninject.dll + True + True + + + + + + + + + ..\..\packages\NSubstitute\lib\net46\NSubstitute.dll + True + True + + + + + + + + + ..\..\packages\NUnit\lib\net45\nunit.framework.dll + True + True + + + + + + + + + ..\..\packages\Shouldly\lib\net451\Shouldly.dll + True + True + + + + + + + + + ..\..\packages\System.Buffers\lib\netstandard2.0\System.Buffers.dll + True + True + + + + + + + + + ..\..\packages\System.Collections.Immutable\lib\netstandard2.0\System.Collections.Immutable.dll + True + True + + + + + + + + + True + + + ..\..\packages\System.Collections.NonGeneric\lib\net46\System.Collections.NonGeneric.dll + False + True + + + + + + + + + True + + + ..\..\packages\System.ComponentModel.Annotations\lib\net461\System.ComponentModel.Annotations.dll + True + True + + + + + + + + + ..\..\packages\System.ComponentModel.Primitives\lib\net45\System.ComponentModel.Primitives.dll + False + True + + + + + + + + + ..\..\packages\System.ComponentModel.TypeConverter\lib\net462\System.ComponentModel.TypeConverter.dll + False + True + + + + + + + + + ..\..\packages\System.Diagnostics.DiagnosticSource\lib\net46\System.Diagnostics.DiagnosticSource.dll + True + True + + + + + + + + + ..\..\packages\System.Diagnostics.FileVersionInfo\lib\net46\System.Diagnostics.FileVersionInfo.dll + False + True + + + + + + + + + ..\..\packages\System.Diagnostics.Process\lib\net461\System.Diagnostics.Process.dll + False + True + + + + + + + + + ..\..\packages\System.Diagnostics.TraceSource\lib\net46\System.Diagnostics.TraceSource.dll + False + True + + + + + + + + + ..\..\packages\System.IO\lib\net462\System.IO.dll + False + True + + + + + + + + + ..\..\packages\System.IO.Pipelines\lib\netstandard2.0\System.IO.Pipelines.dll + True + True + + + + + + + + + ..\..\packages\System.Linq.Expressions\lib\net463\System.Linq.Expressions.dll + False + True + + + + + + + + + ..\..\packages\System.Memory\lib\netstandard2.0\System.Memory.dll + True + True + + + + + + + + + ..\..\packages\System.Net.NameResolution\lib\net46\System.Net.NameResolution.dll + False + True + + + + + + + + + ..\..\packages\System.Net.NetworkInformation\lib\net46\System.Net.NetworkInformation.dll + False + True + + + + + + + + + True + + + ..\..\packages\System.Numerics.Vectors\lib\net46\System.Numerics.Vectors.dll + True + True + + + + + + + + + ..\..\packages\System.Reflection\lib\net462\System.Reflection.dll + False + True + + + + + + + + + ..\..\packages\System.Reflection.Metadata\lib\netstandard2.0\System.Reflection.Metadata.dll + True + True + + + + + + + + + ..\..\packages\System.Reflection.TypeExtensions\lib\net461\System.Reflection.TypeExtensions.dll + True + True + + + + + + + + + True + + + ..\..\packages\System.Runtime\lib\net462\System.Runtime.dll + False + True + + + + + + + + + ..\..\packages\System.Runtime.CompilerServices.Unsafe\lib\netstandard2.0\System.Runtime.CompilerServices.Unsafe.dll + True + True + + + + + + + + + ..\..\packages\System.Runtime.InteropServices.RuntimeInformation\lib\net45\System.Runtime.InteropServices.RuntimeInformation.dll + False + True + + + + + + + + + ..\..\packages\System.Runtime.Serialization.Formatters\lib\net46\System.Runtime.Serialization.Formatters.dll + False + True + + + + + + + + + True + + + ..\..\packages\System.Runtime.Serialization.Primitives\lib\net46\System.Runtime.Serialization.Primitives.dll + False + True + + + + + + + + + ..\..\packages\System.Security.Cryptography.Algorithms\lib\net463\System.Security.Cryptography.Algorithms.dll + False + True + + + + + + + + + ..\..\packages\System.Security.Cryptography.Cng\lib\net47\System.Security.Cryptography.Cng.dll + True + True + + + + + + + + + ..\..\packages\System.Security.Cryptography.Encoding\lib\net46\System.Security.Cryptography.Encoding.dll + False + True + + + + + + + + + ..\..\packages\System.Security.Cryptography.Primitives\lib\net46\System.Security.Cryptography.Primitives.dll + False + True + + + + + + + + + ..\..\packages\System.Text.Encoding.CodePages\lib\net461\System.Text.Encoding.CodePages.dll + True + True + + + + + + + + + ..\..\packages\System.Text.Encodings.Web\lib\netstandard2.0\System.Text.Encodings.Web.dll + True + True + + + + + + + + + ..\..\packages\System.Threading.Tasks.Dataflow\lib\netstandard2.0\System.Threading.Tasks.Dataflow.dll + True + True + + + + + + + + + ..\..\packages\System.Threading.Tasks.Extensions\lib\netstandard2.0\System.Threading.Tasks.Extensions.dll + True + True + + + + + + + + + ..\..\packages\System.Threading.Thread\lib\net46\System.Threading.Thread.dll + False + True + + + + + + + + + ..\..\packages\System.Threading.ThreadPool\lib\net46\System.Threading.ThreadPool.dll + False + True + + + + + + + + + ..\..\packages\System.ValueTuple\lib\net47\System.ValueTuple.dll + True + True + + + + + + + + + ..\..\packages\System.Xml.XmlDocument\lib\net46\System.Xml.XmlDocument.dll + False + True + + + + + + + + + ..\..\packages\System.Xml.XPath\lib\net46\System.Xml.XPath.dll + False + True + + + + + + + + + ..\..\packages\System.Xml.XPath.XmlDocument\lib\net46\System.Xml.XPath.XmlDocument.dll + True + True + + + + + + + + + ..\..\packages\ZooKeeperNetEx\lib\net461\ZooKeeperNetEx.dll + True + True + + + + + \ No newline at end of file diff --git a/tests/Gigya.Microdot.Orleans.Hosting.UnitTests/Logging/OrleansLogAdapterTests.cs b/tests/Gigya.Microdot.Orleans.Hosting.UnitTests/Logging/OrleansLogAdapterTests.cs new file mode 100644 index 00000000..b9ca2b61 --- /dev/null +++ b/tests/Gigya.Microdot.Orleans.Hosting.UnitTests/Logging/OrleansLogAdapterTests.cs @@ -0,0 +1,136 @@ +using NUnit.Framework; +using System; +using System.Collections.Generic; +using System.Diagnostics; +using System.Diagnostics.CodeAnalysis; +using Gigya.Microdot.Interfaces.Logging; +using Gigya.Microdot.Orleans.Hosting.Logging; +using Microsoft.Extensions.Logging; +using Microsoft.Extensions.Logging.Internal; +using NSubstitute; + +namespace Gigya.Microdot.Orleans.Hosting.UnitTests.Logging +{ + [TestFixture] + [SuppressMessage("ReSharper", "ExplicitCallerInfoArgument")] + public class OrleansLogAdapterTests + { + [Test] + public void Log_StateWithValues_ShouldCallLogImplementation() + { + string category = "category"; + ILog log = Substitute.For(); + ILog LogImplementation(string str) => log; + OrleansLogEnrichment logEnrichment = new OrleansLogEnrichment(); + OrleansConfig orleansConfig = new OrleansConfig(); + OrleansConfig OrleansConfigFunc() => orleansConfig; + var orleansLogAdapter = new OrleansLogAdapter(category, LogImplementation, logEnrichment, OrleansConfigFunc); + + EventId eventId = new EventId(42, "my_EventId_Name"); + FormattedLogValues formattedLogValues = new FormattedLogValues("my format {orleansLogKey}", "orleansLogValue"); + string Formatter(FormattedLogValues values, Exception exception) => "formatter result"; + + + orleansLogAdapter.Log(LogLevel.Error, eventId, formattedLogValues, null, Formatter); + + log.Received().Write( + TraceEventType.Error, + Arg.Is>(logDelegateAction => CheckLogDelegate(logDelegateAction)), + Arg.Any(), + Arg.Any(), + Arg.Any()); + } + + private bool CheckLogDelegate(Action logDelegateAction) + { + Type logDelegateActionType = logDelegateAction.Target.GetType(); + var logDelegateActionTypeFields = logDelegateActionType.GetFields(); + + foreach (var field in logDelegateActionTypeFields) + { + if (field.Name == "logMessage") + { + string logMessage = field.GetValue(logDelegateAction.Target) as string; + Assert.AreEqual("formatter result", logMessage); + } + + if (field.Name == "unencryptedTags") + { + if (field.GetValue(logDelegateAction.Target) is Dictionary unencryptedTags) + { + Assert.AreEqual(unencryptedTags["eventId.Id"], 42); + Assert.AreEqual(unencryptedTags["eventId.Name"], "my_EventId_Name"); + Assert.AreEqual(unencryptedTags["IsOrleansLog"], true); + Assert.AreEqual(unencryptedTags["eventHeuristicName"], null); + Assert.AreEqual(unencryptedTags["orleansLogKey"], "orleansLogValue"); + } + } + } + + return true; + } + + [Test] + public void Log_StateWithValues_ShouldNotAddFormatToTags() + { + string category = "category"; + ILog log = Substitute.For(); + ILog LogImplementation(string str) => log; + OrleansLogEnrichment logEnrichment = new OrleansLogEnrichment(); + OrleansConfig orleansConfig = new OrleansConfig(); + OrleansConfig OrleansConfigFunc() => orleansConfig; + var orleansLogAdapter = new OrleansLogAdapter(category, LogImplementation, logEnrichment, OrleansConfigFunc); + + EventId eventId = new EventId(42, "my_EventId_Name"); + FormattedLogValues formattedLogValues = new FormattedLogValues("my format {orleansLogKey}", "orleansLogValue"); + string Formatter(FormattedLogValues values, Exception exception) => "formatter result"; + + + orleansLogAdapter.Log(LogLevel.Error, eventId, formattedLogValues, null, Formatter); + + log.Received().Write( + TraceEventType.Error, + Arg.Is>(logDelegateAction => CheckFormatIsFiltered(logDelegateAction)), + Arg.Any(), + Arg.Any(), + Arg.Any()); + } + + private bool CheckFormatIsFiltered(Action logDelegateAction) + { + Type logDelegateActionType = logDelegateAction.Target.GetType(); + var logDelegateActionTypeFields = logDelegateActionType.GetFields(); + + foreach (var field in logDelegateActionTypeFields) + { + if (field.Name == "unencryptedTags") + { + Assert.AreEqual(field.GetValue(logDelegateAction.Target) is Dictionary unencryptedTags && unencryptedTags.ContainsKey("{OriginalFormat}"), false); + } + } + + return true; + } + + [Test] + public void Log_NullState_ShouldCallLogImplementation() + { + string category = "category"; + ILog log = Substitute.For(); + ILog LogImplementation(string str) => log; + OrleansLogEnrichment logEnrichment = new OrleansLogEnrichment(); + OrleansConfig orleansConfig = new OrleansConfig(); + OrleansConfig OrleansConfigFunc() => orleansConfig; + var orleansLogAdapter = new OrleansLogAdapter(category, LogImplementation, logEnrichment, OrleansConfigFunc); + + EventId eventId = new EventId(42, "my_EventId_Name"); + + string Formatter(FormattedLogValues values, Exception exception) => "formatter result"; + + + orleansLogAdapter.Log(LogLevel.Error, eventId, null, null, Formatter); + + log.Received().Write(TraceEventType.Error, Arg.Any>(), Arg.Any(), Arg.Any(), Arg.Any()); + } + } +} From 72c0ff2a4cfc4bd4d97622de249c65af26752b8f Mon Sep 17 00:00:00 2001 From: Asafi Yosef Date: Sun, 17 Nov 2019 12:44:53 +0200 Subject: [PATCH 2/2] #96733 check max tag count --- .../Logging/OrleansLogAdapter.cs | 6 +- .../.paket/Paket.Restore.targets | 770 +++++++++++------- .../Logging/OrleansLogAdapterTests.cs | 65 +- 3 files changed, 558 insertions(+), 283 deletions(-) diff --git a/Gigya.Microdot.Orleans.Hosting/Logging/OrleansLogAdapter.cs b/Gigya.Microdot.Orleans.Hosting/Logging/OrleansLogAdapter.cs index c3c907f2..74cd7ef9 100644 --- a/Gigya.Microdot.Orleans.Hosting/Logging/OrleansLogAdapter.cs +++ b/Gigya.Microdot.Orleans.Hosting/Logging/OrleansLogAdapter.cs @@ -34,6 +34,7 @@ namespace Gigya.Microdot.Orleans.Hosting.Logging { public class OrleansLogAdapter : ILogger { + private readonly int _maxNumberOfTags = 20; private readonly string[] _logKeysToIgnore = { "{OriginalFormat}" }; private readonly OrleansLogEnrichment _logEnrichment; private readonly ILog _logImplementation; @@ -66,10 +67,13 @@ public void Log(LogLevel logLevel, EventId eventId, TState state, Except {"eventHeuristicName", eventHeuristicName} }; + int numberOfTags = unencryptedTags.Count; + if (state is FormattedLogValues values) { - foreach (var value in values) + for (var i = 0; i < values.Count && i < _maxNumberOfTags - numberOfTags; i++) { + var value = values[i]; if (!_logKeysToIgnore.Contains(value.Key)) { unencryptedTags[value.Key] = value.Value; diff --git a/Gigya.ServiceContract/.paket/Paket.Restore.targets b/Gigya.ServiceContract/.paket/Paket.Restore.targets index e7c1bc0c..c2eb4d49 100644 --- a/Gigya.ServiceContract/.paket/Paket.Restore.targets +++ b/Gigya.ServiceContract/.paket/Paket.Restore.targets @@ -1,276 +1,494 @@ - - - - - - - $(MSBuildAllProjects);$(MSBuildThisFileFullPath) - - true - $(MSBuildThisFileDirectory) - $(MSBuildThisFileDirectory)..\ - $(PaketRootPath)paket-files\paket.restore.cached - $(PaketRootPath)paket.lock - /Library/Frameworks/Mono.framework/Commands/mono - mono - - $(PaketRootPath)paket.exe - $(PaketToolsPath)paket.exe - "$(PaketExePath)" - $(MonoPath) --runtime=v4.0.30319 "$(PaketExePath)" - - - <_PaketExeExtension>$([System.IO.Path]::GetExtension("$(PaketExePath)")) - dotnet "$(PaketExePath)" - - - "$(PaketExePath)" - - $(PaketRootPath)paket.bootstrapper.exe - $(PaketToolsPath)paket.bootstrapper.exe - "$(PaketBootStrapperExePath)" - $(MonoPath) --runtime=v4.0.30319 "$(PaketBootStrapperExePath)" - - - - - true - true - - - - - - - true - $(NoWarn);NU1603 - - - - - /usr/bin/shasum $(PaketRestoreCacheFile) | /usr/bin/awk '{ print $1 }' - /usr/bin/shasum $(PaketLockFilePath) | /usr/bin/awk '{ print $1 }' - - - - - - - - - - - - - $([System.IO.File]::ReadAllText('$(PaketRestoreCacheFile)')) - $([System.IO.File]::ReadAllText('$(PaketLockFilePath)')) - true - false - true - - - - - - - - - $(MSBuildProjectDirectory)\obj\$(MSBuildProjectFile).paket.references.cached - - $(MSBuildProjectFullPath).paket.references - - $(MSBuildProjectDirectory)\$(MSBuildProjectName).paket.references - - $(MSBuildProjectDirectory)\paket.references - $(MSBuildProjectDirectory)\obj\$(MSBuildProjectFile).$(TargetFramework).paket.resolved - true - references-file-or-cache-not-found - - - - - $([System.IO.File]::ReadAllText('$(PaketReferencesCachedFilePath)')) - $([System.IO.File]::ReadAllText('$(PaketOriginalReferencesFilePath)')) - references-file - false - - - - - false - - - - - true - target-framework '$(TargetFramework)' - - - - - - - - - - - - - - - - - $([System.String]::Copy('%(PaketReferencesFileLines.Identity)').Split(',')[0]) - $([System.String]::Copy('%(PaketReferencesFileLines.Identity)').Split(',')[1]) - $([System.String]::Copy('%(PaketReferencesFileLines.Identity)').Split(',')[4]) - - - %(PaketReferencesFileLinesInfo.PackageVersion) - All - - - - - $(MSBuildProjectDirectory)/obj/$(MSBuildProjectFile).paket.clitools - - - - - - - - - $([System.String]::Copy('%(PaketCliToolFileLines.Identity)').Split(',')[0]) - $([System.String]::Copy('%(PaketCliToolFileLines.Identity)').Split(',')[1]) - - - %(PaketCliToolFileLinesInfo.PackageVersion) - - - - - - - - - - false - - - - - - <_NuspecFilesNewLocation Include="$(BaseIntermediateOutputPath)$(Configuration)\*.nuspec"/> - - - - $(MSBuildProjectDirectory)/$(MSBuildProjectFile) - true - false - true - $(BaseIntermediateOutputPath)$(Configuration) - $(BaseIntermediateOutputPath) - - - - <_NuspecFiles Include="$(AdjustedNuspecOutputPath)\*.nuspec"/> - - - - - - - - - - - - - - - - + + + + + + + $(MSBuildAllProjects);$(MSBuildThisFileFullPath) + + $(MSBuildVersion) + 15.0.0 + false + true + + true + $(MSBuildThisFileDirectory) + $(MSBuildThisFileDirectory)..\ + $(PaketRootPath)paket-files\paket.restore.cached + $(PaketRootPath)paket.lock + classic + proj + assembly + native + /Library/Frameworks/Mono.framework/Commands/mono + mono + + + $(PaketRootPath)paket.bootstrapper.exe + $(PaketToolsPath)paket.bootstrapper.exe + $([System.IO.Path]::GetDirectoryName("$(PaketBootStrapperExePath)"))\ + + "$(PaketBootStrapperExePath)" + $(MonoPath) --runtime=v4.0.30319 "$(PaketBootStrapperExePath)" + + + + + true + true + + + True + + + False + + $(BaseIntermediateOutputPath.TrimEnd('\').TrimEnd('\/')) + + + + + + + + + $(PaketRootPath)paket + $(PaketToolsPath)paket + + + + + + $(PaketRootPath)paket.exe + $(PaketToolsPath)paket.exe + + + + + + <_DotnetToolsJson Condition="Exists('$(PaketRootPath)/.config/dotnet-tools.json')">$([System.IO.File]::ReadAllText("$(PaketRootPath)/.config/dotnet-tools.json")) + <_ConfigContainsPaket Condition=" '$(_DotnetToolsJson)' != ''">$(_DotnetToolsJson.Contains('"paket"')) + <_ConfigContainsPaket Condition=" '$(_ConfigContainsPaket)' == ''">false + + + + + + + + + + + <_PaketCommand>dotnet paket + + + + + + $(PaketToolsPath)paket + $(PaketBootStrapperExeDir)paket + + + paket + + + + + <_PaketExeExtension>$([System.IO.Path]::GetExtension("$(PaketExePath)")) + <_PaketCommand Condition=" '$(_PaketCommand)' == '' AND '$(_PaketExeExtension)' == '.dll' ">dotnet "$(PaketExePath)" + <_PaketCommand Condition=" '$(_PaketCommand)' == '' AND '$(OS)' != 'Windows_NT' AND '$(_PaketExeExtension)' == '.exe' ">$(MonoPath) --runtime=v4.0.30319 "$(PaketExePath)" + <_PaketCommand Condition=" '$(_PaketCommand)' == '' ">"$(PaketExePath)" + + + + + + + + + + + + + + + + + + + + + true + $(NoWarn);NU1603;NU1604;NU1605;NU1608 + false + true + + + + + + + + + $([System.IO.File]::ReadAllText('$(PaketRestoreCacheFile)')) + + + + + + + $([System.Text.RegularExpressions.Regex]::Split(`%(Identity)`, `": "`)[0].Replace(`"`, ``).Replace(` `, ``)) + $([System.Text.RegularExpressions.Regex]::Split(`%(Identity)`, `": "`)[1].Replace(`"`, ``).Replace(` `, ``)) + + + + + %(PaketRestoreCachedKeyValue.Value) + %(PaketRestoreCachedKeyValue.Value) + + + + + true + false + true + + + + + true + + + + + + + + + + + + + + + + + + + $(PaketIntermediateOutputPath)\$(MSBuildProjectFile).paket.references.cached + + $(MSBuildProjectFullPath).paket.references + + $(MSBuildProjectDirectory)\$(MSBuildProjectName).paket.references + + $(MSBuildProjectDirectory)\paket.references + + false + true + true + references-file-or-cache-not-found + + + + + $([System.IO.File]::ReadAllText('$(PaketReferencesCachedFilePath)')) + $([System.IO.File]::ReadAllText('$(PaketOriginalReferencesFilePath)')) + references-file + false + + + + + false + + + + + true + target-framework '$(TargetFramework)' or '$(TargetFrameworks)' files @(PaketResolvedFilePaths) + + + + + + + + + + + false + true + + + + + + + + + + + $([System.String]::Copy('%(PaketReferencesFileLines.Identity)').Split(',').Length) + $([System.String]::Copy('%(PaketReferencesFileLines.Identity)').Split(',')[0]) + $([System.String]::Copy('%(PaketReferencesFileLines.Identity)').Split(',')[1]) + $([System.String]::Copy('%(PaketReferencesFileLines.Identity)').Split(',')[4]) + $([System.String]::Copy('%(PaketReferencesFileLines.Identity)').Split(',')[5]) + + + %(PaketReferencesFileLinesInfo.PackageVersion) + All + runtime + runtime + true + true + + + + + $(PaketIntermediateOutputPath)/$(MSBuildProjectFile).paket.clitools + + + + + + + + + $([System.String]::Copy('%(PaketCliToolFileLines.Identity)').Split(',')[0]) + $([System.String]::Copy('%(PaketCliToolFileLines.Identity)').Split(',')[1]) + + + %(PaketCliToolFileLinesInfo.PackageVersion) + + + + + + + + + + false + + + + + + <_NuspecFilesNewLocation Include="$(PaketIntermediateOutputPath)\$(Configuration)\*.nuspec"/> + + + + + + $(MSBuildProjectDirectory)/$(MSBuildProjectFile) + true + false + true + false + true + false + true + false + true + $(PaketIntermediateOutputPath)\$(Configuration) + $(PaketIntermediateOutputPath) + + + + <_NuspecFiles Include="$(AdjustedNuspecOutputPath)\*.$(PackageVersion.Split(`+`)[0]).nuspec"/> + + + + + + + + + + + + + + + + + + + + + diff --git a/tests/Gigya.Microdot.Orleans.Hosting.UnitTests/Logging/OrleansLogAdapterTests.cs b/tests/Gigya.Microdot.Orleans.Hosting.UnitTests/Logging/OrleansLogAdapterTests.cs index b9ca2b61..3d7d8594 100644 --- a/tests/Gigya.Microdot.Orleans.Hosting.UnitTests/Logging/OrleansLogAdapterTests.cs +++ b/tests/Gigya.Microdot.Orleans.Hosting.UnitTests/Logging/OrleansLogAdapterTests.cs @@ -58,11 +58,11 @@ private bool CheckLogDelegate(Action logDelegateAction) { if (field.GetValue(logDelegateAction.Target) is Dictionary unencryptedTags) { - Assert.AreEqual(unencryptedTags["eventId.Id"], 42); - Assert.AreEqual(unencryptedTags["eventId.Name"], "my_EventId_Name"); - Assert.AreEqual(unencryptedTags["IsOrleansLog"], true); - Assert.AreEqual(unencryptedTags["eventHeuristicName"], null); - Assert.AreEqual(unencryptedTags["orleansLogKey"], "orleansLogValue"); + Assert.AreEqual(42, unencryptedTags["eventId.Id"]); + Assert.AreEqual("my_EventId_Name", unencryptedTags["eventId.Name"]); + Assert.AreEqual(true, unencryptedTags["IsOrleansLog"]); + Assert.AreEqual(null, unencryptedTags["eventHeuristicName"]); + Assert.AreEqual("orleansLogValue", unencryptedTags["orleansLogKey"]); } } } @@ -105,7 +105,7 @@ private bool CheckFormatIsFiltered(Action logDelegateAction) { if (field.Name == "unencryptedTags") { - Assert.AreEqual(field.GetValue(logDelegateAction.Target) is Dictionary unencryptedTags && unencryptedTags.ContainsKey("{OriginalFormat}"), false); + Assert.AreEqual(false, field.GetValue(logDelegateAction.Target) is Dictionary unencryptedTags && unencryptedTags.ContainsKey("{OriginalFormat}")); } } @@ -132,5 +132,58 @@ public void Log_NullState_ShouldCallLogImplementation() log.Received().Write(TraceEventType.Error, Arg.Any>(), Arg.Any(), Arg.Any(), Arg.Any()); } + + [Test] + public void Log_LargeFormattedLogValues_TagsDontExceedMaxNumber() + { + string category = "category"; + ILog log = Substitute.For(); + ILog LogImplementation(string str) => log; + OrleansLogEnrichment logEnrichment = new OrleansLogEnrichment(); + OrleansConfig orleansConfig = new OrleansConfig(); + OrleansConfig OrleansConfigFunc() => orleansConfig; + var orleansLogAdapter = new OrleansLogAdapter(category, LogImplementation, logEnrichment, OrleansConfigFunc); + + EventId eventId = new EventId(42, "my_EventId_Name"); + FormattedLogValues formattedLogValues = new FormattedLogValues("{1}{2}{3}{4}{5}{6}{7}{8}{9}{10}{11}{12}{13}{14}{15}{16}{17}{18}{19}{20}{21}{22}{23}{24}{25}{26}", new object[]{'a','b', 'c', 'd', 'e', 'f','g', 'h', 'i','j','k', 'm', 'n', 'l', 'o', 'p', 'q', 'r', 's', 't', 'u','v','w','x','y','z'}); + string Formatter(FormattedLogValues values, Exception exception) => "formatter result"; + + + orleansLogAdapter.Log(LogLevel.Error, eventId, formattedLogValues, null, Formatter); + + log.Received().Write( + TraceEventType.Error, + Arg.Is>(logDelegateAction => CheckLogTags(logDelegateAction)), + Arg.Any(), + Arg.Any(), + Arg.Any()); + } + + private bool CheckLogTags(Action logDelegateAction) + { + Type logDelegateActionType = logDelegateAction.Target.GetType(); + var logDelegateActionTypeFields = logDelegateActionType.GetFields(); + + foreach (var field in logDelegateActionTypeFields) + { + if (field.Name == "logMessage") + { + string logMessage = field.GetValue(logDelegateAction.Target) as string; + Assert.AreEqual("formatter result", logMessage); + } + + if (field.Name == "unencryptedTags") + { + if (field.GetValue(logDelegateAction.Target) is Dictionary unencryptedTags) + { + Assert.AreEqual('a', unencryptedTags["1"]); + Assert.AreEqual('p', unencryptedTags["16"]); + Assert.AreEqual(20, unencryptedTags.Count); + } + } + } + + return true; + } } }