Skip to content

Commit

Permalink
Merge branch 'master' into AppSettingThreadSafe
Browse files Browse the repository at this point in the history
  • Loading branch information
snakefoot committed Jun 12, 2019
2 parents 7209cf0 + 7dfbf65 commit 7a7f54f
Show file tree
Hide file tree
Showing 135 changed files with 3,324 additions and 1,345 deletions.
4 changes: 2 additions & 2 deletions .travis.yml
@@ -1,8 +1,8 @@
language: csharp

mono: 5.2.0
mono: 5.8.0
dotnet: 2.0.0
dist: trusty
dist: bionic


install:
Expand Down
63 changes: 63 additions & 0 deletions CHANGELOG.md
Expand Up @@ -4,6 +4,69 @@ Date format: (year/month/day)

## Change Log

### V4.6.4 (2019/05/28)

#### Bugfixes

- [#3392](https://github.com/NLog/NLog/pull/3392) NLog.Schema: Added missing defaultAction attribute on filters element in XSD (@304NotModified)
- [#3415](https://github.com/NLog/NLog/pull/3415) AsyncWrapper in Blocking Mode can cause deadlock (@snakefoot)

#### Features

- [#3430](https://github.com/NLog/NLog/pull/3430) Added "Properties" property on Logger for reading and editing properties.(@snakefoot, @304NotModified)
- [#3423](https://github.com/NLog/NLog/pull/3423) ${all-event-properties}: Added IncludeEmptyValues option (@304NotModified)
- [#3394](https://github.com/NLog/NLog/pull/3394) ${when}, support for non-string values (@304NotModified)
- [#3398](https://github.com/NLog/NLog/pull/3398) ${whenEmpty} support for non-string values (@snakefoot, @304NotModified)
- [#3391](https://github.com/NLog/NLog/pull/3391) Added ${environment-user} (@snakefoot)
- [#3389](https://github.com/NLog/NLog/pull/3389) Log4JXmlEventLayout - Added support for configuration of Parameters (@snakefoot)
- [#3411](https://github.com/NLog/NLog/pull/3411) LoggingConfigurationParser - Recognize LoggingRule.RuleName property (@snakefoot)

#### Improvements

- [#3393](https://github.com/NLog/NLog/pull/3393) Update package descriptions to note the issues with <PackageReference> (@304NotModified)
- [#3409](https://github.com/NLog/NLog/pull/3409) Various XSD improvements (NLog.Schema package) (@304NotModified)

#### Performance

- [#3398](https://github.com/NLog/NLog/pull/3398) ${whenEmpty} faster rendering of string values (@snakefoot, @304NotModified)
- [#3405](https://github.com/NLog/NLog/pull/3405) FilteringTargetWrapper: Add support for batch writing (@snakefoot, @304NotModified)
- [#3405](https://github.com/NLog/NLog/pull/3405) PostFilteringTargetWrapper: performance optimizations (@snakefoot, @304NotModified)
- [#3435](https://github.com/NLog/NLog/pull/3435) Async / buffering wrapper: Improve performance when blocking (@snakefoot)
- [#3434](https://github.com/NLog/NLog/pull/3434) ObjectReflectionCache - Skip property-reflection for IFormattable (@snakefoot)

### V4.6.3 (2019/04/30)

#### Bugfixes

- [#3345](https://github.com/NLog/NLog/pull/3345) Fixed potential memory issue and message duplication with large strings (@snakefoot)
- [#3316](https://github.com/NLog/NLog/pull/3316) TargetWithContext - serialize MDC and MDLC values properly (@304NotModified)

#### Features

- [#3298](https://github.com/NLog/NLog/pull/3298) Added WithProperty and SetProperty on Logger (@snakefoot)
- [#3329](https://github.com/NLog/NLog/pull/3329) ${EventProperties} - Added ObjectPath for rendering nested property (@snakefoot, @304NotModified)
- [#3337](https://github.com/NLog/NLog/pull/3337) ${ShortDate} added support for IRawValue + IStringValueRenderer (@snakefoot)
- [#3328](https://github.com/NLog/NLog/pull/3328) Added truncate ambient property, e.g. ${message:truncate=80} (@snakefoot)
- [#3278](https://github.com/NLog/NLog/pull/3278) ConsoleTarget & ColoredConsoleTarget - Added AutoFlush and improve default flush behavior (@snakefoot)

#### Improvements

- [#3322](https://github.com/NLog/NLog/pull/3322) FileTarget - Introduced EnableFileDeleteSimpleMonitor without FileSystemWatcher for non-Windows (@snakefoot)
- [#3332](https://github.com/NLog/NLog/pull/3332) LogFactory - GetLogger should validate name of logger (@snakefoot)
- [#3320](https://github.com/NLog/NLog/pull/3320) FallbackGroupTarget - Fixed potential issue with WINDOWS_PHONE (@snakefoot)
- [#3261](https://github.com/NLog/NLog/pull/3261) NLog config file loading: use process name (e.g. applicationname.exe.nlog) when app.config is not available (@snakefoot)

#### Performance

- [#3311](https://github.com/NLog/NLog/pull/3311) Split string - avoid allocation of object array. Added StringHelpers.SplitAndTrimTokens (@snakefoot)
- [#3305](https://github.com/NLog/NLog/pull/3305) AppSettingLayoutRenderer - Mark as ThreadSafe and ThreadAgnostic (@snakefoot)

#### Misc

- [#3338](https://github.com/NLog/NLog/pull/3338) Update docs of various context classes (@304NotModified)
- [#3288](https://github.com/NLog/NLog/pull/3288) Move NLogPackageLoaders for better unittest debugging experience of NLog (@304NotModified)
- [#3274](https://github.com/NLog/NLog/pull/3274) Make HttpNetworkSender mockable, add unit test, introduce NSubsitute (@304NotModified)
- 10 pull requests with refactorings (@snakefoot, @304NotModified)

### V4.6.2 (2019/04/02)

Expand Down
12 changes: 6 additions & 6 deletions README.md
Expand Up @@ -7,12 +7,12 @@
[![license](https://img.shields.io/github/license/mashape/apistatus.svg)]()


[![](https://sonarcloud.io/api/project_badges/measure?project=nlog&metric=ncloc)](https://sonarcloud.io/dashboard/?id=nlog)
[![](https://sonarcloud.io/api/project_badges/measure?project=nlog&metric=bugs)](https://sonarcloud.io/dashboard/?id=nlog)
[![](https://sonarcloud.io/api/project_badges/measure?project=nlog&metric=vulnerabilities)](https://sonarcloud.io/dashboard/?id=nlog)
[![](https://sonarcloud.io/api/project_badges/measure?project=nlog&metric=code_smells)](https://sonarcloud.io/project/issues?id=nlog&resolved=false&types=CODE_SMELL)
[![](https://sonarcloud.io/api/project_badges/measure?project=nlog&metric=duplicated_lines_density)](https://sonarcloud.io/component_measures/domain/Duplications?id=nlog)
[![](https://sonarcloud.io/api/project_badges/measure?project=nlog&metric=sqale_debt_ratio)](https://sonarcloud.io/dashboard/?id=nlog)
[![](https://sonarcloud.io/api/project_badges/measure?project=nlog&metric=ncloc&branch=dev)](https://sonarcloud.io/dashboard/?id=nlog&branch=dev)
[![](https://sonarcloud.io/api/project_badges/measure?project=nlog&metric=bugs&branch=dev)](https://sonarcloud.io/dashboard/?id=nlog&branch=dev)
[![](https://sonarcloud.io/api/project_badges/measure?project=nlog&metric=vulnerabilities&branch=dev)](https://sonarcloud.io/dashboard/?id=nlog&branch=dev)
[![](https://sonarcloud.io/api/project_badges/measure?project=nlog&metric=code_smells&branch=dev)](https://sonarcloud.io/project/issues?id=nlog&resolved=false&types=CODE_SMELL&branch=dev)
[![](https://sonarcloud.io/api/project_badges/measure?project=nlog&metric=duplicated_lines_density&branch=dev)](https://sonarcloud.io/component_measures/domain/Duplications?id=nlog&branch=dev)
[![](https://sonarcloud.io/api/project_badges/measure?project=nlog&metric=sqale_debt_ratio&branch=dev)](https://sonarcloud.io/dashboard/?id=nlog&branch=dev)
[![codecov.io](https://codecov.io/github/NLog/NLog/coverage.svg?branch=dev)](https://codecov.io/github/NLog/NLog?branch=dev)

<!--
Expand Down
16 changes: 9 additions & 7 deletions build.ps1
Expand Up @@ -5,7 +5,7 @@ dotnet --version
# dotnet restore .\src\NLog\
# dotnet pack .\src\NLog\ --configuration release --include-symbols -o ..\..\artifacts

$versionPrefix = "4.6.2"
$versionPrefix = "4.6.4"
$versionSuffix = ""
$versionFile = $versionPrefix + "." + ${env:APPVEYOR_BUILD_NUMBER}
$versionProduct = $versionPrefix;
Expand All @@ -18,21 +18,23 @@ if ($env:APPVEYOR_PULL_REQUEST_NUMBER)
$versionSuffix = "PR" + $env:APPVEYOR_PULL_REQUEST_NUMBER
}

# download nuget.exe

$sourceNugetExe = "https://dist.nuget.org/win-x86-commandline/latest/nuget.exe"
$targetNugetExe = "tools\nuget.exe"
Invoke-WebRequest $sourceNugetExe -OutFile $targetNugetExe
if (-Not (test-path $targetNugetExe))
{
# download nuget.exe
$sourceNugetExe = "https://dist.nuget.org/win-x86-commandline/latest/nuget.exe"
Invoke-WebRequest $sourceNugetExe -OutFile $targetNugetExe
}

msbuild /t:Restore,Pack .\src\NLog\ /p:targetFrameworks='"net45;net40-client;net35;netstandard1.3;netstandard1.5;netstandard2.0;sl4;sl5;wp8;monoandroid44;xamarinios10"' /p:VersionPrefix=$versionPrefix /p:VersionSuffix=$versionSuffix /p:FileVersion=$versionFile /p:ProductVersion=$versionProduct /p:Configuration=Release /p:IncludeSymbols=true /p:SymbolPackageFormat=snupkg /p:PackageOutputPath=..\..\artifacts /verbosity:minimal
msbuild /t:Restore,Pack .\src\NLog\ /p:targetFrameworks='"net45;net40-client;net35;netstandard1.3;netstandard1.5;netstandard2.0;sl4;sl5;wp8;monoandroid44;xamarinios10"' /p:VersionPrefix=$versionPrefix /p:VersionSuffix=$versionSuffix /p:FileVersion=$versionFile /p:ProductVersion=$versionProduct /p:Configuration=Release /p:IncludeSymbols=true /p:SymbolPackageFormat=snupkg /p:PackageOutputPath=..\..\artifacts /verbosity:minimal /maxcpucount
if (-Not $LastExitCode -eq 0)
{ exit $LastExitCode }

function create-package($packageName)
{

$path = ".\src\$packageName\"
msbuild /t:Restore,Pack $path /p:VersionPrefix=$versionPrefix /p:VersionSuffix=$versionSuffix /p:FileVersion=$versionFile /p:ProductVersion=$versionProduct /p:Configuration=Release /p:IncludeSymbols=true /p:SymbolPackageFormat=snupkg /p:PackageOutputPath=..\..\artifacts /verbosity:minimal
msbuild /t:Restore,Pack $path /p:VersionPrefix=$versionPrefix /p:VersionSuffix=$versionSuffix /p:FileVersion=$versionFile /p:ProductVersion=$versionProduct /p:Configuration=Release /p:IncludeSymbols=true /p:SymbolPackageFormat=snupkg /p:PackageOutputPath=..\..\artifacts /verbosity:minimal /maxcpucount
if (-Not $LastExitCode -eq 0)
{ exit $LastExitCode }

Expand Down
91 changes: 91 additions & 0 deletions src/NLog/Attributes/LogLevelTypeConverter.cs
@@ -0,0 +1,91 @@
//
// Copyright (c) 2004-2019 Jaroslaw Kowalski <jaak@jkowalski.net>, Kim Christensen, Julian Verdurmen
//
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions
// are met:
//
// * Redistributions of source code must retain the above copyright notice,
// this list of conditions and the following disclaimer.
//
// * Redistributions in binary form must reproduce the above copyright notice,
// this list of conditions and the following disclaimer in the documentation
// and/or other materials provided with the distribution.
//
// * Neither the name of Jaroslaw Kowalski nor the names of its
// contributors may be used to endorse or promote products derived from this
// software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS 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 OWNER 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.
//

namespace NLog.Attributes
{
using System;
using System.ComponentModel;
using System.Globalization;

/// <summary>
/// Support <see cref="NLog.LogLevel"/> implementation of <see cref="IConvertible"/>
/// </summary>
public class LogLevelTypeConverter : TypeConverter
{
/// <inheritdoc/>
public override bool CanConvertFrom(ITypeDescriptorContext context, Type sourceType)
{
return sourceType == typeof(string) || IsNumericType(sourceType) || base.CanConvertFrom(context, sourceType);
}

/// <inheritdoc/>
public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value)
{
if (value?.GetType() == typeof(string))
return LogLevel.FromString(value.ToString());
else if (IsNumericType(value?.GetType()))
return LogLevel.FromOrdinal(Convert.ToInt32(value));
else
return base.ConvertFrom(context, culture, value);
}

/// <inheritdoc/>
public override bool CanConvertTo(ITypeDescriptorContext context, Type destinationType)
{
return destinationType == typeof(string) || IsNumericType(destinationType) || base.CanConvertTo(context, destinationType);
}

/// <inheritdoc/>
public override object ConvertTo(ITypeDescriptorContext context, CultureInfo culture, object value, Type destinationType)
{
if (value is LogLevel logLevel)
{
if (destinationType == typeof(string))
return logLevel.ToString();
else if (IsNumericType(destinationType))
return Convert.ChangeType(logLevel.Ordinal, destinationType, culture);
}
return base.ConvertTo(context, culture, value, destinationType);
}

private static bool IsNumericType(Type sourceType)
{
return sourceType == typeof(int) ||
sourceType == typeof(uint) ||
sourceType == typeof(long) ||
sourceType == typeof(ulong) ||
sourceType == typeof(short) ||
sourceType == typeof(ushort);
}
}
}
7 changes: 6 additions & 1 deletion src/NLog/Common/LogEventInfoBuffer.cs
Expand Up @@ -65,10 +65,15 @@ public LogEventInfoBuffer(int size, bool growAsNeeded, int growLimit)
}

/// <summary>
/// Gets the number of items in the array.
/// Gets the capacity of the buffer
/// </summary>
public int Size => _buffer.Length;

/// <summary>
/// Gets the number of items in the buffer
/// </summary>
internal int Count { get { lock (_lockObject) return _count; } }

/// <summary>
/// Adds the specified log event to the buffer.
/// </summary>
Expand Down
2 changes: 1 addition & 1 deletion src/NLog/Conditions/ConditionMethodExpression.cs
Expand Up @@ -186,7 +186,7 @@ public override string ToString()
protected override object EvaluateNode(LogEventInfo context)
{
int parameterOffset = _acceptsLogEvent ? 1 : 0;
int parameterDefaults = _lateBoundMethodDefaultParameters != null ? _lateBoundMethodDefaultParameters.Length : 0;
int parameterDefaults = _lateBoundMethodDefaultParameters?.Length ?? 0;

var callParameters = new object[MethodParameters.Count + parameterOffset + parameterDefaults];

Expand Down
18 changes: 14 additions & 4 deletions src/NLog/Config/LoggerNameMatcher.cs
Expand Up @@ -89,15 +89,25 @@ public static LoggerNameMatcher Create(string loggerNamePattern)
return new ContainsLoggerNameMatcher(loggerNamePattern);
if (starPos2 < 0)
{
if (starPos1 == 0)
return new EndsWithLoggerNameMatcher(loggerNamePattern);
if (starPos1 == loggerNamePattern.Length - 1)
return new StartsWithLoggerNameMatcher(loggerNamePattern);
var loggerNameMatcher = CreateStartsOrEndsWithLoggerNameMatcher(loggerNamePattern, starPos1);
if (loggerNameMatcher != null)
{
return loggerNameMatcher;
}
}
}
return new MultiplePatternLoggerNameMatcher(loggerNamePattern);
}

private static LoggerNameMatcher CreateStartsOrEndsWithLoggerNameMatcher(string loggerNamePattern, int starPos1)
{
if (starPos1 == 0)
return new EndsWithLoggerNameMatcher(loggerNamePattern);
if (starPos1 == loggerNamePattern.Length - 1)
return new StartsWithLoggerNameMatcher(loggerNamePattern);
return null;
}

/// <summary>
/// Returns the argument passed to <see cref="LoggerNameMatcher.Create(string)"/>
/// </summary>
Expand Down

0 comments on commit 7a7f54f

Please sign in to comment.