Skip to content

Commit fd2f0a9

Browse files
authored
Enable logging in framework services (#166)
1 parent 32a8717 commit fd2f0a9

File tree

4 files changed

+67
-74
lines changed

4 files changed

+67
-74
lines changed

samples/MvcApp/Web.config

Lines changed: 60 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,16 @@
66
<configuration>
77
<configSections>
88
<!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->
9-
<section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
9+
<section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false"/>
1010
</configSections>
1111
<connectionStrings>
12-
<add name="DefaultConnection" connectionString="Data Source=(LocalDb)\MSSQLLocalDB;AttachDbFilename=|DataDirectory|\aspnet-MvcApp-20220502113315.mdf;Initial Catalog=aspnet-MvcApp-20220502113315;Integrated Security=True" providerName="System.Data.SqlClient" />
12+
<add name="DefaultConnection" connectionString="Data Source=(LocalDb)\MSSQLLocalDB;AttachDbFilename=|DataDirectory|\aspnet-MvcApp-20220502113315.mdf;Initial Catalog=aspnet-MvcApp-20220502113315;Integrated Security=True" providerName="System.Data.SqlClient"/>
1313
</connectionStrings>
1414
<appSettings>
15-
<add key="webpages:Version" value="3.0.0.0" />
16-
<add key="webpages:Enabled" value="false" />
17-
<add key="ClientValidationEnabled" value="true" />
18-
<add key="UnobtrusiveJavaScriptEnabled" value="true" />
15+
<add key="webpages:Version" value="3.0.0.0"/>
16+
<add key="webpages:Enabled" value="false"/>
17+
<add key="ClientValidationEnabled" value="true"/>
18+
<add key="UnobtrusiveJavaScriptEnabled" value="true"/>
1919
</appSettings>
2020
<!--
2121
For a description of web.config changes see http://go.microsoft.com/fwlink/?LinkId=235367.
@@ -28,13 +28,17 @@
2828
<system.web>
2929
<compilation debug="true" targetFramework="4.7.2">
3030
<assemblies>
31-
<add assembly="netstandard, Version=2.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51" />
31+
<add assembly="netstandard, Version=2.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51"/>
3232
</assemblies>
3333
</compilation>
34-
<httpRuntime targetFramework="4.7.2" />
34+
<httpRuntime targetFramework="4.7.2"/>
3535
</system.web>
3636
<runtime>
3737
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
38+
<dependentAssembly>
39+
<assemblyIdentity name="Microsoft.Extensions.Logging.Abstractions" publicKeyToken="ADB9793829DDAE60" culture="neutral"/>
40+
<bindingRedirect oldVersion="0.0.0.0-6.0.0.1" newVersion="6.0.0.1"/>
41+
</dependentAssembly>
3842
<dependentAssembly>
3943
<assemblyIdentity name="System.Text.Encodings.Web" publicKeyToken="CC7B13FFCD2DDD51" culture="neutral"/>
4044
<bindingRedirect oldVersion="0.0.0.0-6.0.0.0" newVersion="6.0.0.0"/>
@@ -44,105 +48,105 @@
4448
<bindingRedirect oldVersion="0.0.0.0-4.0.3.0" newVersion="4.0.3.0"/>
4549
</dependentAssembly>
4650
<dependentAssembly>
47-
<assemblyIdentity name="System.ComponentModel.Annotations" publicKeyToken="B03F5F7F11D50A3A" culture="neutral" />
48-
<bindingRedirect oldVersion="0.0.0.0-4.2.1.0" newVersion="4.2.1.0" />
51+
<assemblyIdentity name="System.ComponentModel.Annotations" publicKeyToken="B03F5F7F11D50A3A" culture="neutral"/>
52+
<bindingRedirect oldVersion="0.0.0.0-4.2.1.0" newVersion="4.2.1.0"/>
4953
</dependentAssembly>
5054
<dependentAssembly>
51-
<assemblyIdentity name="System.Runtime.CompilerServices.Unsafe" publicKeyToken="B03F5F7F11D50A3A" culture="neutral" />
52-
<bindingRedirect oldVersion="0.0.0.0-6.0.0.0" newVersion="6.0.0.0" />
55+
<assemblyIdentity name="System.Runtime.CompilerServices.Unsafe" publicKeyToken="B03F5F7F11D50A3A" culture="neutral"/>
56+
<bindingRedirect oldVersion="0.0.0.0-6.0.0.0" newVersion="6.0.0.0"/>
5357
</dependentAssembly>
5458
<dependentAssembly>
55-
<assemblyIdentity name="Antlr3.Runtime" publicKeyToken="eb42632606e9261f" />
56-
<bindingRedirect oldVersion="0.0.0.0-3.5.0.2" newVersion="3.5.0.2" />
59+
<assemblyIdentity name="Antlr3.Runtime" publicKeyToken="eb42632606e9261f"/>
60+
<bindingRedirect oldVersion="0.0.0.0-3.5.0.2" newVersion="3.5.0.2"/>
5761
</dependentAssembly>
5862
<dependentAssembly>
59-
<assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" />
60-
<bindingRedirect oldVersion="0.0.0.0-12.0.0.0" newVersion="12.0.0.0" />
63+
<assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed"/>
64+
<bindingRedirect oldVersion="0.0.0.0-12.0.0.0" newVersion="12.0.0.0"/>
6165
</dependentAssembly>
6266
<dependentAssembly>
63-
<assemblyIdentity name="System.Web.Optimization" publicKeyToken="31bf3856ad364e35" />
64-
<bindingRedirect oldVersion="1.0.0.0-1.1.0.0" newVersion="1.1.0.0" />
67+
<assemblyIdentity name="System.Web.Optimization" publicKeyToken="31bf3856ad364e35"/>
68+
<bindingRedirect oldVersion="1.0.0.0-1.1.0.0" newVersion="1.1.0.0"/>
6569
</dependentAssembly>
6670
<dependentAssembly>
67-
<assemblyIdentity name="WebGrease" publicKeyToken="31bf3856ad364e35" />
68-
<bindingRedirect oldVersion="0.0.0.0-1.6.5135.21930" newVersion="1.6.5135.21930" />
71+
<assemblyIdentity name="WebGrease" publicKeyToken="31bf3856ad364e35"/>
72+
<bindingRedirect oldVersion="0.0.0.0-1.6.5135.21930" newVersion="1.6.5135.21930"/>
6973
</dependentAssembly>
7074
<dependentAssembly>
71-
<assemblyIdentity name="System.Web.Helpers" publicKeyToken="31bf3856ad364e35" />
72-
<bindingRedirect oldVersion="1.0.0.0-3.0.0.0" newVersion="3.0.0.0" />
75+
<assemblyIdentity name="System.Web.Helpers" publicKeyToken="31bf3856ad364e35"/>
76+
<bindingRedirect oldVersion="1.0.0.0-3.0.0.0" newVersion="3.0.0.0"/>
7377
</dependentAssembly>
7478
<dependentAssembly>
75-
<assemblyIdentity name="System.Web.WebPages" publicKeyToken="31bf3856ad364e35" />
76-
<bindingRedirect oldVersion="1.0.0.0-3.0.0.0" newVersion="3.0.0.0" />
79+
<assemblyIdentity name="System.Web.WebPages" publicKeyToken="31bf3856ad364e35"/>
80+
<bindingRedirect oldVersion="1.0.0.0-3.0.0.0" newVersion="3.0.0.0"/>
7781
</dependentAssembly>
7882
<dependentAssembly>
79-
<assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35" />
80-
<bindingRedirect oldVersion="1.0.0.0-5.2.7.0" newVersion="5.2.7.0" />
83+
<assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35"/>
84+
<bindingRedirect oldVersion="1.0.0.0-5.2.7.0" newVersion="5.2.7.0"/>
8185
</dependentAssembly>
8286
<dependentAssembly>
83-
<assemblyIdentity name="Microsoft.Owin" publicKeyToken="31bf3856ad364e35" culture="neutral" />
84-
<bindingRedirect oldVersion="0.0.0.0-4.2.1.0" newVersion="4.2.1.0" />
87+
<assemblyIdentity name="Microsoft.Owin" publicKeyToken="31bf3856ad364e35" culture="neutral"/>
88+
<bindingRedirect oldVersion="0.0.0.0-4.2.1.0" newVersion="4.2.1.0"/>
8589
</dependentAssembly>
8690
<dependentAssembly>
87-
<assemblyIdentity name="Microsoft.Owin.Security" publicKeyToken="31bf3856ad364e35" culture="neutral" />
88-
<bindingRedirect oldVersion="0.0.0.0-4.2.1.0" newVersion="4.2.1.0" />
91+
<assemblyIdentity name="Microsoft.Owin.Security" publicKeyToken="31bf3856ad364e35" culture="neutral"/>
92+
<bindingRedirect oldVersion="0.0.0.0-4.2.1.0" newVersion="4.2.1.0"/>
8993
</dependentAssembly>
9094
<dependentAssembly>
91-
<assemblyIdentity name="Microsoft.Owin.Security.OAuth" publicKeyToken="31bf3856ad364e35" culture="neutral" />
92-
<bindingRedirect oldVersion="0.0.0.0-4.2.1.0" newVersion="4.2.1.0" />
95+
<assemblyIdentity name="Microsoft.Owin.Security.OAuth" publicKeyToken="31bf3856ad364e35" culture="neutral"/>
96+
<bindingRedirect oldVersion="0.0.0.0-4.2.1.0" newVersion="4.2.1.0"/>
9397
</dependentAssembly>
9498
<dependentAssembly>
95-
<assemblyIdentity name="Microsoft.Owin.Security.Cookies" publicKeyToken="31bf3856ad364e35" culture="neutral" />
96-
<bindingRedirect oldVersion="0.0.0.0-4.2.1.0" newVersion="4.2.1.0" />
99+
<assemblyIdentity name="Microsoft.Owin.Security.Cookies" publicKeyToken="31bf3856ad364e35" culture="neutral"/>
100+
<bindingRedirect oldVersion="0.0.0.0-4.2.1.0" newVersion="4.2.1.0"/>
97101
</dependentAssembly>
98102
<dependentAssembly>
99-
<assemblyIdentity name="System.Runtime.CompilerServices.Unsafe" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
100-
<bindingRedirect oldVersion="0.0.0.0-6.0.0.0" newVersion="6.0.0.0" />
103+
<assemblyIdentity name="System.Runtime.CompilerServices.Unsafe" publicKeyToken="b03f5f7f11d50a3a" culture="neutral"/>
104+
<bindingRedirect oldVersion="0.0.0.0-6.0.0.0" newVersion="6.0.0.0"/>
101105
</dependentAssembly>
102106
<dependentAssembly>
103-
<assemblyIdentity name="Microsoft.Extensions.Primitives" publicKeyToken="adb9793829ddae60" culture="neutral" />
104-
<bindingRedirect oldVersion="0.0.0.0-6.0.0.0" newVersion="6.0.0.0" />
107+
<assemblyIdentity name="Microsoft.Extensions.Primitives" publicKeyToken="adb9793829ddae60" culture="neutral"/>
108+
<bindingRedirect oldVersion="0.0.0.0-6.0.0.0" newVersion="6.0.0.0"/>
105109
</dependentAssembly>
106110
<dependentAssembly>
107-
<assemblyIdentity name="Microsoft.Extensions.Configuration.Abstractions" publicKeyToken="adb9793829ddae60" culture="neutral" />
108-
<bindingRedirect oldVersion="0.0.0.0-6.0.0.0" newVersion="6.0.0.0" />
111+
<assemblyIdentity name="Microsoft.Extensions.Configuration.Abstractions" publicKeyToken="adb9793829ddae60" culture="neutral"/>
112+
<bindingRedirect oldVersion="0.0.0.0-6.0.0.0" newVersion="6.0.0.0"/>
109113
</dependentAssembly>
110114
<dependentAssembly>
111-
<assemblyIdentity name="Microsoft.Extensions.DependencyInjection.Abstractions" publicKeyToken="adb9793829ddae60" culture="neutral" />
112-
<bindingRedirect oldVersion="0.0.0.0-6.0.0.0" newVersion="6.0.0.0" />
115+
<assemblyIdentity name="Microsoft.Extensions.DependencyInjection.Abstractions" publicKeyToken="adb9793829ddae60" culture="neutral"/>
116+
<bindingRedirect oldVersion="0.0.0.0-6.0.0.0" newVersion="6.0.0.0"/>
113117
</dependentAssembly>
114118
<dependentAssembly>
115-
<assemblyIdentity name="Microsoft.Extensions.FileProviders.Abstractions" publicKeyToken="adb9793829ddae60" culture="neutral" />
116-
<bindingRedirect oldVersion="0.0.0.0-6.0.0.0" newVersion="6.0.0.0" />
119+
<assemblyIdentity name="Microsoft.Extensions.FileProviders.Abstractions" publicKeyToken="adb9793829ddae60" culture="neutral"/>
120+
<bindingRedirect oldVersion="0.0.0.0-6.0.0.0" newVersion="6.0.0.0"/>
117121
</dependentAssembly>
118122
<dependentAssembly>
119-
<assemblyIdentity name="Microsoft.AspNetCore.DataProtection.Abstractions" publicKeyToken="adb9793829ddae60" culture="neutral" />
120-
<bindingRedirect oldVersion="0.0.0.0-6.0.7.0" newVersion="6.0.7.0" />
123+
<assemblyIdentity name="Microsoft.AspNetCore.DataProtection.Abstractions" publicKeyToken="adb9793829ddae60" culture="neutral"/>
124+
<bindingRedirect oldVersion="0.0.0.0-6.0.7.0" newVersion="6.0.7.0"/>
121125
</dependentAssembly>
122126
</assemblyBinding>
123127
</runtime>
124128
<system.codedom>
125129
<compilers>
126-
<compiler extension=".cs" language="c#;cs;csharp" warningLevel="4" compilerOptions="/langversion:7.3 /nowarn:1659;1699;1701;612;618" type="Microsoft.CodeDom.Providers.DotNetCompilerPlatform.CSharpCodeProvider, Microsoft.CodeDom.Providers.DotNetCompilerPlatform, Version=3.6.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
127-
<compiler extension=".vb" language="vb;vbs;visualbasic;vbscript" warningLevel="4" compilerOptions="/langversion:default /nowarn:41008,40000,40008 /define:_MYTYPE=\&quot;Web\&quot; /optionInfer+" type="Microsoft.CodeDom.Providers.DotNetCompilerPlatform.VBCodeProvider, Microsoft.CodeDom.Providers.DotNetCompilerPlatform, Version=3.6.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
130+
<compiler extension=".cs" language="c#;cs;csharp" warningLevel="4" compilerOptions="/langversion:7.3 /nowarn:1659;1699;1701;612;618" type="Microsoft.CodeDom.Providers.DotNetCompilerPlatform.CSharpCodeProvider, Microsoft.CodeDom.Providers.DotNetCompilerPlatform, Version=3.6.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
131+
<compiler extension=".vb" language="vb;vbs;visualbasic;vbscript" warningLevel="4" compilerOptions="/langversion:default /nowarn:41008,40000,40008 /define:_MYTYPE=\&quot;Web\&quot; /optionInfer+" type="Microsoft.CodeDom.Providers.DotNetCompilerPlatform.VBCodeProvider, Microsoft.CodeDom.Providers.DotNetCompilerPlatform, Version=3.6.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
128132
</compilers>
129133
</system.codedom>
130134
<system.webServer>
131135
<modules>
132-
<remove name="SystemWebAdapterModule" />
133-
<add name="SystemWebAdapterModule" type="Microsoft.AspNetCore.SystemWebAdapters.SystemWebAdapterModule, Microsoft.AspNetCore.SystemWebAdapters.FrameworkServices" preCondition="managedHandler" />
136+
<remove name="SystemWebAdapterModule"/>
137+
<add name="SystemWebAdapterModule" type="Microsoft.AspNetCore.SystemWebAdapters.SystemWebAdapterModule, Microsoft.AspNetCore.SystemWebAdapters.FrameworkServices" preCondition="managedHandler"/>
134138
</modules>
135139
<handlers>
136-
<remove name="ExtensionlessUrlHandler-Integrated-4.0" />
137-
<remove name="OPTIONSVerbHandler" />
138-
<remove name="TRACEVerbHandler" />
139-
<add name="ExtensionlessUrlHandler-Integrated-4.0" path="*." verb="*" type="System.Web.Handlers.TransferRequestHandler" preCondition="integratedMode,runtimeVersionv4.0" />
140+
<remove name="ExtensionlessUrlHandler-Integrated-4.0"/>
141+
<remove name="OPTIONSVerbHandler"/>
142+
<remove name="TRACEVerbHandler"/>
143+
<add name="ExtensionlessUrlHandler-Integrated-4.0" path="*." verb="*" type="System.Web.Handlers.TransferRequestHandler" preCondition="integratedMode,runtimeVersionv4.0"/>
140144
</handlers>
141145
</system.webServer>
142146
<entityFramework>
143-
<defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlConnectionFactory, EntityFramework" />
147+
<defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlConnectionFactory, EntityFramework"/>
144148
<providers>
145-
<provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
149+
<provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer"/>
146150
</providers>
147151
</entityFramework>
148152
</configuration>

src/Microsoft.AspNetCore.SystemWebAdapters.FrameworkServices/Microsoft.AspNetCore.SystemWebAdapters.FrameworkServices.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
<PackageReference Include="System.Text.Json" Version="6.0.0" />
3333
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="6.0.0" />
3434
<PackageReference Include="Microsoft.Extensions.Options" Version="6.0.0" />
35+
<PackageReference Include="Microsoft.Extensions.Logging" Version="6.0.0" />
3536
</ItemGroup>
3637

3738
<ItemGroup>

src/Microsoft.AspNetCore.SystemWebAdapters.FrameworkServices/SystemWebAdapterConfiguration.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,11 @@ public static ISystemWebAdapterBuilder AddSystemWebAdapters(this HttpApplication
2424
{
2525
if (application.Application[Key] is null)
2626
{
27-
application.Application[Key] = new SystemWebAdapterBuilder(new ServiceCollection());
27+
var services = new ServiceCollection();
28+
29+
services.AddLogging();
30+
31+
application.Application[Key] = new SystemWebAdapterBuilder(services);
2832

2933
// If a service provider has been created, ensure it's disposed at
3034
// application shutdown.

src/Services/SessionState/Serialization/BinarySessionSerializer.cs

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,8 @@
88
using System.Text;
99
using System.Threading;
1010
using System.Threading.Tasks;
11-
using Microsoft.Extensions.Options;
12-
13-
#if !NETFRAMEWORK
1411
using Microsoft.Extensions.Logging;
15-
16-
#endif
12+
using Microsoft.Extensions.Options;
1713

1814
namespace Microsoft.AspNetCore.SystemWebAdapters.SessionState.Serialization;
1915

@@ -24,15 +20,6 @@ internal partial class BinarySessionSerializer : ISessionSerializer
2420
private readonly SessionSerializerOptions _options;
2521
private readonly ISessionKeySerializer _serializer;
2622

27-
#if NETFRAMEWORK
28-
public BinarySessionSerializer(ISessionKeySerializer serializer, IOptions<SessionSerializerOptions> options)
29-
{
30-
_serializer = serializer ?? throw new ArgumentNullException(nameof(serializer));
31-
_options = options?.Value ?? throw new ArgumentNullException(nameof(options));
32-
}
33-
34-
partial void LogSerialization(string key);
35-
#else
3623
private readonly ILogger<BinarySessionSerializer> _logger;
3724

3825
public BinarySessionSerializer(ISessionKeySerializer serializer, IOptions<SessionSerializerOptions> options, ILogger<BinarySessionSerializer> logger)
@@ -47,7 +34,6 @@ public BinarySessionSerializer(ISessionKeySerializer serializer, IOptions<Sessio
4734

4835
[LoggerMessage(EventId = 1, Level = LogLevel.Warning, Message = "Could not deserialize unknown session key '{Key}'")]
4936
partial void LogDeserialization(string key);
50-
#endif
5137

5238
public void Write(ISessionState state, BinaryWriter writer)
5339
{
@@ -123,12 +109,10 @@ public ISessionState Read(BinaryReader reader)
123109

124110
if (state.UnknownKeys is { Count: > 0 } unknownKeys)
125111
{
126-
#if !NETFRAMEWORK
127112
foreach (var unknown in unknownKeys)
128113
{
129114
LogDeserialization(unknown);
130115
}
131-
#endif
132116

133117
if (_options.ThrowOnUnknownSessionKey)
134118
{

0 commit comments

Comments
 (0)