Skip to content

Commit 1c1bbcf

Browse files
committed
Updated to NLog 5.0 preview 2
1 parent b98cd07 commit 1c1bbcf

44 files changed

Lines changed: 226 additions & 60 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

appveyor.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ deploy:
2727
test_script:
2828
- nuget.exe install OpenCover -ExcludeVersion -DependencyVersion Ignore
2929
- OpenCover\tools\OpenCover.Console.exe -register:user -returntargetcode -target:"%xunit20%\xunit.console.x86.exe" -targetargs:"\"c:\projects\nlogweb\tests\NLog.Web.Tests\bin\Release\net452\NLog.Web.Tests.dll\" -appveyor -noshadow" -returntargetcode -filter:"+[NLog.Web]*" -excludebyattribute:*.ExcludeFromCodeCoverage* -hideskipped:All -oldstyle -output:coverage.xml
30+
- OpenCover\tools\OpenCover.Console.exe -register:user -returntargetcode -target:"%xunit20%\xunit.console.x86.exe" -targetargs:"\"c:\projects\nlogweb\tests\NLog.Web.Tests\bin\Release\net461\NLog.Web.Tests.dll\" -appveyor -noshadow" -returntargetcode -filter:"+[NLog.Web]*" -excludebyattribute:*.ExcludeFromCodeCoverage* -hideskipped:All -oldstyle -mergeoutput -output:coverage.xml
3031
- OpenCover\tools\OpenCover.Console.exe -register:user -returntargetcode -target:"%xunit20%\xunit.console.x86.exe" -targetargs:"\"c:\projects\nlogweb\tests\NLog.Web.AspNetCore.Tests\bin\Release\net461\NLog.Web.AspNetCore.Tests.dll\" -appveyor -noshadow" -filter:"+[NLog.Web]*" -excludebyattribute:*.ExcludeFromCodeCoverage* -hideskipped:All -oldstyle -mergeoutput -output:coverage.xml
3132
- pip install codecov
3233
- codecov -f "coverage.xml"

examples/ASP.NET 4.6.1/Visual Studio 2017/ASP.NET 4.6.1 - VS2017/ASP.NET 4.6.1 - VS2017.csproj

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,7 @@
4545
</PropertyGroup>
4646
<ItemGroup>
4747
<Reference Include="Microsoft.CSharp" />
48-
<Reference Include="NLog, Version=4.0.0.0, Culture=neutral, PublicKeyToken=5120e14c03d0593c, processorArchitecture=MSIL">
49-
<HintPath>..\..\..\..\packages\NLog.4.5.8\lib\net45\NLog.dll</HintPath>
50-
</Reference>
48+
<Reference Include="NLog" />
5149
<Reference Include="System" />
5250
<Reference Include="System.Data" />
5351
<Reference Include="System.Drawing" />

examples/ASP.NET 4.6.1/Visual Studio 2017/ASP.NET 4.6.1 - VS2017/packages.config

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
<package id="Microsoft.Web.Infrastructure" version="1.0.0.0" targetFramework="net461" />
1414
<package id="Modernizr" version="2.8.3" targetFramework="net461" />
1515
<package id="Newtonsoft.Json" version="11.0.1" targetFramework="net461" />
16-
<package id="NLog" version="4.6.2" targetFramework="net461" />
16+
<package id="NLog" version="5.0.0-preview.2" targetFramework="net461" />
1717
<package id="System.Diagnostics.DiagnosticSource" version="4.4.1" targetFramework="net461" />
1818
<package id="WebGrease" version="1.6.0" targetFramework="net461" />
1919
</packages>

src/NLog.Web.AspNetCore/LayoutRenderers/AspNetEnvironmentLayoutRenderer.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ namespace NLog.Web.LayoutRenderers
1919
/// </summary>
2020
[LayoutRenderer("aspnet-environment")]
2121
[ThreadAgnostic]
22-
[ThreadSafe]
2322
public class AspNetEnvironmentLayoutRenderer : LayoutRenderer
2423
{
2524
private static IHostEnvironment _hostEnvironment;

src/NLog.Web.AspNetCore/LayoutRenderers/AspNetUserClaimLayoutRenderer.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ namespace NLog.Web.LayoutRenderers
1212
/// ASP.NET User ClaimType Value Lookup.
1313
/// </summary>
1414
[LayoutRenderer("aspnet-user-claim")]
15-
[ThreadSafe]
1615
public class AspNetUserClaimLayoutRenderer : AspNetLayoutRendererBase
1716
{
1817
/// <summary>

src/NLog.Web.AspNetCore/NLog.Web.AspNetCore.csproj

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22
<PropertyGroup>
33
<RestoreProjectStyle>PackageReference</RestoreProjectStyle>
4-
<TargetFrameworks>net461;netstandard2.0;netcoreapp3.0</TargetFrameworks>
4+
<TargetFrameworks>net461;netstandard2.0;netcoreapp3.1;net5.0</TargetFrameworks>
55
<Product>NLog.Web.AspNetCore v$(VersionPrefix)</Product>
66
<Description>
77
NLog LoggerProvider for Microsoft.Extensions.Logging and ASP.NET Core platform. Adds helpers and layout renderers for websites and web applications.
@@ -30,7 +30,7 @@ See also https://github.com/NLog/NLog.Web/releases
3030
<RepositoryType>git</RepositoryType>
3131
<RepositoryUrl>git://github.com/NLog/NLog.Web</RepositoryUrl>
3232
<SignAssembly>true</SignAssembly>
33-
<AssemblyVersion>4.0.0.0</AssemblyVersion>
33+
<AssemblyVersion>5.0.0.0</AssemblyVersion>
3434
<AssemblyOriginatorKeyFile>NLog.snk</AssemblyOriginatorKeyFile>
3535
<PublicSign Condition=" '$(OS)' != 'Windows_NT' ">true</PublicSign>
3636
<RootNamespace>NLog.Web</RootNamespace>
@@ -56,12 +56,16 @@ See also https://github.com/NLog/NLog.Web/releases
5656
<Title>ASP.NET Core 2 integration for NLog - .NET Standard 2</Title>
5757
<DefineConstants>$(DefineConstants);ASP_NET_CORE;ASP_NET_CORE2</DefineConstants>
5858
</PropertyGroup>
59-
<PropertyGroup Condition=" '$(TargetFramework)' == 'netcoreapp3.0' ">
60-
<Title>ASP.NET Core 3 integration for NLog - .NET Core 3</Title>
59+
<PropertyGroup Condition=" '$(TargetFramework)' == 'netcoreapp3.1' ">
60+
<Title>ASP.NET Core 3 integration for NLog - .NET Core 3.1</Title>
61+
<DefineConstants>$(DefineConstants);ASP_NET_CORE;ASP_NET_CORE3</DefineConstants>
62+
</PropertyGroup>
63+
<PropertyGroup Condition=" '$(TargetFramework)' == 'net5.0' ">
64+
<Title>ASP.NET Core 5 integration for NLog - .NET 5.0</Title>
6165
<DefineConstants>$(DefineConstants);ASP_NET_CORE;ASP_NET_CORE3</DefineConstants>
6266
</PropertyGroup>
6367
<ItemGroup>
64-
<PackageReference Include="NLog.Extensions.Logging" Version="1.7.4" />
68+
<PackageReference Include="NLog.Extensions.Logging" Version="5.0.0-preview.2" />
6569
</ItemGroup>
6670
<ItemGroup Condition=" '$(TargetFramework)' == 'netstandard2.0' or '$(TargetFramework)' == 'net461' ">
6771
<!-- Fixed to 2.1.0 as 2.1 is Long Term Supported (LTS) and works with vanilla .NET Core 2.1 SDK -->
@@ -72,7 +76,10 @@ See also https://github.com/NLog/NLog.Web/releases
7276
<ItemGroup>
7377
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.0.0" PrivateAssets="All" />
7478
</ItemGroup>
75-
<ItemGroup Condition=" '$(TargetFramework)' == 'netcoreapp3.0' ">
79+
<ItemGroup Condition=" '$(TargetFramework)' == 'netcoreapp3.1' ">
80+
<FrameworkReference Include="Microsoft.AspNetCore.App" />
81+
</ItemGroup>
82+
<ItemGroup Condition=" '$(TargetFramework)' == 'net5.0' ">
7683
<FrameworkReference Include="Microsoft.AspNetCore.App" />
7784
</ItemGroup>
7885
<ItemGroup>
Lines changed: 155 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,155 @@
1+
//
2+
// Copyright (c) 2004-2021 Jaroslaw Kowalski <jaak@jkowalski.net>, Kim Christensen, Julian Verdurmen
3+
//
4+
// All rights reserved.
5+
//
6+
// Redistribution and use in source and binary forms, with or without
7+
// modification, are permitted provided that the following conditions
8+
// are met:
9+
//
10+
// * Redistributions of source code must retain the above copyright notice,
11+
// this list of conditions and the following disclaimer.
12+
//
13+
// * Redistributions in binary form must reproduce the above copyright notice,
14+
// this list of conditions and the following disclaimer in the documentation
15+
// and/or other materials provided with the distribution.
16+
//
17+
// * Neither the name of Jaroslaw Kowalski nor the names of its
18+
// contributors may be used to endorse or promote products derived from this
19+
// software without specific prior written permission.
20+
//
21+
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
22+
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23+
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24+
// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
25+
// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
26+
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
27+
// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
28+
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
29+
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
30+
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
31+
// THE POSSIBILITY OF SUCH DAMAGE.
32+
//
33+
34+
namespace NLog.Web.Internal
35+
{
36+
using NLog.Common;
37+
using System;
38+
39+
/// <summary>
40+
/// A cyclic buffer of <see cref="LogEventInfo"/> object.
41+
/// </summary>
42+
internal class LogEventInfoBuffer
43+
{
44+
private readonly object _lockObject = new object();
45+
private readonly bool _growAsNeeded;
46+
private readonly int _growLimit;
47+
48+
private AsyncLogEventInfo[] _buffer;
49+
private int _getPointer;
50+
private int _putPointer;
51+
private int _count;
52+
53+
/// <summary>
54+
/// Initializes a new instance of the <see cref="LogEventInfoBuffer" /> class.
55+
/// </summary>
56+
/// <param name="size">Buffer size.</param>
57+
/// <param name="growAsNeeded">Whether buffer should grow as it becomes full.</param>
58+
/// <param name="growLimit">The maximum number of items that the buffer can grow to.</param>
59+
public LogEventInfoBuffer(int size, bool growAsNeeded, int growLimit)
60+
{
61+
_growAsNeeded = growAsNeeded;
62+
_buffer = new AsyncLogEventInfo[size];
63+
_growLimit = growLimit;
64+
_getPointer = 0;
65+
_putPointer = 0;
66+
}
67+
68+
/// <summary>
69+
/// Gets the capacity of the buffer
70+
/// </summary>
71+
public int Size => _buffer.Length;
72+
73+
/// <summary>
74+
/// Gets the number of items in the buffer
75+
/// </summary>
76+
internal int Count { get { lock (_lockObject) return _count; } }
77+
78+
/// <summary>
79+
/// Adds the specified log event to the buffer.
80+
/// </summary>
81+
/// <param name="eventInfo">Log event.</param>
82+
/// <returns>The number of items in the buffer.</returns>
83+
public int Append(AsyncLogEventInfo eventInfo)
84+
{
85+
lock (_lockObject)
86+
{
87+
// make room for additional item
88+
if (_count >= _buffer.Length)
89+
{
90+
if (_growAsNeeded && _buffer.Length < _growLimit)
91+
{
92+
// create a new buffer, copy data from current
93+
int newLength = _buffer.Length * 2;
94+
if (newLength >= _growLimit)
95+
{
96+
newLength = _growLimit;
97+
}
98+
99+
InternalLogger.Trace("Enlarging LogEventInfoBuffer from {0} to {1}", _buffer.Length, newLength);
100+
var newBuffer = new AsyncLogEventInfo[newLength];
101+
Array.Copy(_buffer, 0, newBuffer, 0, _buffer.Length);
102+
_buffer = newBuffer;
103+
}
104+
else
105+
{
106+
// lose the oldest item
107+
_getPointer = _getPointer + 1;
108+
}
109+
}
110+
111+
// put the item
112+
_putPointer = _putPointer % _buffer.Length;
113+
_buffer[_putPointer] = eventInfo;
114+
_putPointer = _putPointer + 1;
115+
_count++;
116+
if (_count >= _buffer.Length)
117+
{
118+
_count = _buffer.Length;
119+
}
120+
121+
return _count;
122+
}
123+
}
124+
125+
/// <summary>
126+
/// Gets the array of events accumulated in the buffer and clears the buffer as one atomic operation.
127+
/// </summary>
128+
/// <returns>Events in the buffer.</returns>
129+
public AsyncLogEventInfo[] GetEventsAndClear()
130+
{
131+
lock (_lockObject)
132+
{
133+
int cnt = _count;
134+
if (cnt == 0)
135+
return new AsyncLogEventInfo[0];
136+
137+
var returnValue = new AsyncLogEventInfo[cnt];
138+
139+
for (int i = 0; i < cnt; ++i)
140+
{
141+
int p = (_getPointer + i) % _buffer.Length;
142+
var e = _buffer[p];
143+
_buffer[p] = default(AsyncLogEventInfo); // we don't want memory leaks
144+
returnValue[i] = e;
145+
}
146+
147+
_count = 0;
148+
_getPointer = 0;
149+
_putPointer = 0;
150+
151+
return returnValue;
152+
}
153+
}
154+
}
155+
}

src/NLog.Web/LayoutRenderers/AspNetApplicationValueLayoutRenderer.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ namespace NLog.Web.LayoutRenderers
3333
/// </code>
3434
/// </example>
3535
[LayoutRenderer("aspnet-application")]
36-
[ThreadSafe]
3736
public class AspNetApplicationValueLayoutRenderer : AspNetLayoutRendererBase
3837
{
3938
/// <summary>

src/NLog.Web/NLog.Web.csproj

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22
<PropertyGroup>
33
<RestoreProjectStyle>PackageReference</RestoreProjectStyle>
4-
<TargetFrameworks>net35</TargetFrameworks>
4+
<TargetFrameworks>net35;net46</TargetFrameworks>
55
<Product>NLog.Web v$(VersionPrefix)</Product>
66
<Description>
77
NLog logging for ASP.NET and ASP.NET MVC. Includes targets and layout renderers for websites and web applications.
@@ -33,7 +33,7 @@ See https://github.com/NLog/NLog.Web/releases
3333
<RepositoryUrl>https://github.com/NLog/NLog.Web.git</RepositoryUrl>
3434

3535
<SignAssembly>true</SignAssembly>
36-
<AssemblyVersion>4.0.0.0</AssemblyVersion>
36+
<AssemblyVersion>5.0.0.0</AssemblyVersion>
3737
<AssemblyOriginatorKeyFile>NLog.snk</AssemblyOriginatorKeyFile>
3838

3939
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
@@ -49,7 +49,7 @@ See https://github.com/NLog/NLog.Web/releases
4949
<DownloadFile SourceUrl="https://nlog-project.org/N.png" DestinationFolder="$(MSBuildThisFileDirectory)" />
5050
</Target>
5151
<ItemGroup>
52-
<PackageReference Include="NLog" Version="4.7.11" />
52+
<PackageReference Include="NLog" Version="5.0.0-preview.2" />
5353
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.0.0" PrivateAssets="All" />
5454
</ItemGroup>
5555
<ItemGroup>

src/NLog.Web/Targets/Wrappers/AspNetBufferingTargetWrapper.cs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
using NLog.Common;
55
using NLog.Targets;
66
using NLog.Targets.Wrappers;
7+
using NLog.Web.Internal;
78

89
namespace NLog.Web.Targets.Wrappers
910
{
@@ -163,7 +164,7 @@ protected override void CloseTarget()
163164
/// <param name="logEvent">The log event.</param>
164165
protected override void Write(AsyncLogEventInfo logEvent)
165166
{
166-
LogEventInfoBuffer buffer = GetRequestBuffer();
167+
var buffer = GetRequestBuffer();
167168
if (buffer != null)
168169
{
169170
WrappedTarget.PrecalculateVolatileLayouts(logEvent.LogEvent);
@@ -178,27 +179,27 @@ protected override void Write(AsyncLogEventInfo logEvent)
178179
}
179180
}
180181

181-
private LogEventInfoBuffer GetRequestBuffer()
182+
private NLog.Web.Internal.LogEventInfoBuffer GetRequestBuffer()
182183
{
183184
HttpContext context = HttpContext.Current;
184185
if (context == null)
185186
{
186187
return null;
187188
}
188189

189-
return context.Items[dataSlot] as LogEventInfoBuffer;
190+
return context.Items[dataSlot] as NLog.Web.Internal.LogEventInfoBuffer;
190191
}
191192

192193
private void OnBeginRequest(object sender, EventArgs args)
193194
{
194195
InternalLogger.Trace("Setting up ASP.NET request buffer.");
195196
HttpContext context = HttpContext.Current;
196-
context.Items[dataSlot] = new LogEventInfoBuffer(BufferSize, GrowBufferAsNeeded, BufferGrowLimit);
197+
context.Items[dataSlot] = new NLog.Web.Internal.LogEventInfoBuffer(BufferSize, GrowBufferAsNeeded, BufferGrowLimit);
197198
}
198199

199200
private void OnEndRequest(object sender, EventArgs args)
200201
{
201-
LogEventInfoBuffer buffer = GetRequestBuffer();
202+
var buffer = GetRequestBuffer();
202203
if (buffer != null)
203204
{
204205
InternalLogger.Trace("Sending buffered events to wrapped target: {0}.", WrappedTarget);

0 commit comments

Comments
 (0)