Skip to content

Commit

Permalink
Merge branch 'release/6.1.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
huorswords committed Jan 24, 2022
2 parents b57d331 + fe1896a commit a7f9087
Show file tree
Hide file tree
Showing 58 changed files with 1,129 additions and 1,932 deletions.
32 changes: 32 additions & 0 deletions .github/workflows/pr.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
name: 👀 Pull Request Checks
on:
workflow_dispatch:
pull_request:
types: [opened, edited, synchronize]

env:
SOLUTION_PATH: ./src/Microsoft.Extensions.Logging.Log4net.sln

jobs:
build:
name: 🚀🧪 Test PR
runs-on: windows-latest
steps:
- name: 🛎 Checkout
uses: actions/[email protected]
with:
persist-credentials: false

- name: 🏗 Setup dotnet
uses: actions/setup-dotnet@v1
with:
dotnet-version: |
6.0.x
5.0.x
3.1.x
- name: 🛠 Restore packages
run: dotnet restore "${{ env.SOLUTION_PATH }}"

- name: 🧪 Test
run: dotnet test "${{ env.SOLUTION_PATH }}"
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -174,4 +174,4 @@ Thank you very much to all contributors & users by its collaboration, and specia
* [@kastwey](https://github.com/kastwey) by the feature to allow to replace values of log4net.config using the *Microsoft.Extensions.Configuration*.
* [@willwolfram18](https://github.com/willwolfram18) by bugfixing `Log4NetScopeFactory` usage when provided in `Log4NetProviderOptions`.
* [@lscorcia](https://github.com/lscorcia) by the fix of incorrect call stack when logging.
* [@JustusGreiberORGADATA](https://github.com/JustusGreiberORGADATA) by the inclusion of a configurable logging event factory.
* [@JustusGreiberORGADATA](https://github.com/JustusGreiberORGADATA) by the inclusion of a configurable logging event factory, and `IExternalScope` provider implementation.
153 changes: 76 additions & 77 deletions deploy/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,84 +2,83 @@ pool:
vmimage: windows-latest

trigger:
- main
- main

variables:
BuildConfiguration: 'Release'
BuildConfiguration: "Release"

steps:
- task: UseDotNet@2
displayName: 'Use .NET Core sdk 1.1.x'
inputs:
version: 1.1.x

- task: UseDotNet@2
displayName: 'Use .NET Core sdk 2.x'
inputs:
version: 2.x

- task: UseDotNet@2
displayName: 'Use .NET Core sdk 3.0.x'
inputs:
version: 3.0.x

- task: UseDotNet@2
displayName: 'Use .NET Core sdk 3.1.x'
inputs:
version: 3.1.x

- task: UseDotNet@2
displayName: 'Use .NET Core sdk 5.0.x'
inputs:
version: 5.0.x

- task: UseDotNet@2
displayName: 'Use .NET Core sdk 6.0.x'
inputs:
version: 6.0.x

- task: DownloadSecureFile@1
name: snkFile # The name with which to reference the secure file's path on the agent, like $(snkFile.secureFilePath)
inputs:
secureFile: Microsoft.Extensions.Logging.Log4Net.AspNetCoreKey.snk

- bash: |
cp $SNKFILE_SECUREFILEPATH $BUILD_SOURCESDIRECTORY/src/Microsoft.Extensions.Logging.Log4Net.AspNetCore
displayName: 'Bash Script'

- task: DotNetCoreCLI@2
displayName: 'dotnet restore'
inputs:
command: restore
projects: '$(Build.SourcesDirectory)/**/*csproj'

- task: DotNetCoreCLI@2
displayName: 'dotnet build'
inputs:
projects: |
$(Build.SourcesDirectory)/**/*csproj
!$(Build.SourcesDirectory)/**/NetFrameworkv4_7_2/*.csproj
arguments: '--configuration $(BuildConfiguration)'

- task: DotNetCoreCLI@2
displayName: 'dotnet test'
inputs:
command: test
projects: |
$(Build.SourcesDirectory)/**/*.csproj
!$(Build.SourcesDirectory)/**/NetFramework.v472.Tests/*.csproj
arguments: '--configuration $(BuildConfiguration)'

- task: DotNetCoreCLI@2
displayName: 'dotnet pack'
inputs:
command: pack
includesymbols: true
packagesToPack: '$(Build.SourcesDirectory)/**/Microsoft.Extensions.Logging.Log4Net.AspNetCore.csproj'

- task: PublishBuildArtifacts@1
displayName: 'Publish Artifact: nuget'
inputs:
ArtifactName: nuget


- task: UseDotNet@2
displayName: "Use .NET Core sdk 1.1.x"
inputs:
version: 1.1.x

- task: UseDotNet@2
displayName: "Use .NET Core sdk 2.x"
inputs:
version: 2.x

- task: UseDotNet@2
displayName: "Use .NET Core sdk 3.0.x"
inputs:
version: 3.0.x

- task: UseDotNet@2
displayName: "Use .NET Core sdk 3.1.x"
inputs:
version: 3.1.x

- task: UseDotNet@2
displayName: "Use .NET Core sdk 5.0.x"
inputs:
version: 5.0.x

- task: UseDotNet@2
displayName: "Use .NET Core sdk 6.0.x"
inputs:
version: 6.0.x

- task: DownloadSecureFile@1
name: snkFile # The name with which to reference the secure file's path on the agent, like $(snkFile.secureFilePath)
inputs:
secureFile: Microsoft.Extensions.Logging.Log4Net.AspNetCoreKey.snk

- bash: |
cp $SNKFILE_SECUREFILEPATH $BUILD_SOURCESDIRECTORY/src/Microsoft.Extensions.Logging.Log4Net.AspNetCore
displayName: "Bash Script"
- task: DotNetCoreCLI@2
displayName: "dotnet restore"
inputs:
command: restore
projects: "$(Build.SourcesDirectory)/**/*csproj"

- task: DotNetCoreCLI@2
displayName: "dotnet build"
inputs:
projects: |
$(Build.SourcesDirectory)/**/*csproj
!$(Build.SourcesDirectory)/**/NetFrameworkv4_7_2/*.csproj
arguments: "--configuration $(BuildConfiguration)"

- task: DotNetCoreCLI@2
displayName: "dotnet test"
inputs:
command: test
projects: |
$(Build.SourcesDirectory)/**/*.csproj
!$(Build.SourcesDirectory)/**/NetFramework.v472.Tests/*.csproj
arguments: "--configuration $(BuildConfiguration)"

- task: DotNetCoreCLI@2
displayName: "dotnet pack"
inputs:
command: pack
includesymbols: true
packagesToPack: "$(Build.SourcesDirectory)/**/Microsoft.Extensions.Logging.Log4Net.AspNetCore.csproj"
versioningScheme: "off"

- task: PublishBuildArtifacts@1
displayName: "Publish Artifact: nuget"
inputs:
ArtifactName: nuget
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,17 @@ namespace Microsoft.Extensions.Logging.Log4Net.AspNetCore.Entities
/// <summary>
/// Represents a candidate for a log message that should be printed. This candidate will either be accepted or denied by the logger that is trying to print it.
/// </summary>
/// <remarks>
/// <para>
/// This is a readonly struct to reduce memory pressure, but because it is quite large (definitly larger than the recommended 16 bytes)
/// it needs to be passed as a reference (with the in keyword) to make a difference.
/// </para>
/// <para>
/// See <see href="https://devblogs.microsoft.com/premier-developer/the-in-modifier-and-the-readonly-structs-in-c/"/> for more information.
/// </para>
/// </remarks>
/// <typeparam name="TState">Type of the state that is used to format the error message.</typeparam>
public class MessageCandidate<TState>
public readonly struct MessageCandidate<TState>
{
public MessageCandidate(LogLevel logLevel, EventId eventId, TState state, Exception exception, Func<TState, Exception, string> formatter)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ public interface ILog4NetLoggingEventFactory
/// <param name="logger">The logger the event is created for.</param>
/// <param name="options">The options of the log4net logging provider.</param>
/// <returns>A <see cref="log4net.Core.LoggingEvent"/> that is ready to be logged with the provided logger or null if the candidate should be dropped.</returns>
LoggingEvent CreateLoggingEvent<TState>(MessageCandidate<TState> messageCandidate, log4net.Core.ILogger logger, Log4NetProviderOptions options);
LoggingEvent CreateLoggingEvent<TState>(
in MessageCandidate<TState> messageCandidate,
log4net.Core.ILogger logger,
Log4NetProviderOptions options,
IExternalScopeProvider scopeProvider);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ public static ILoggerFactory AddLog4Net(this ILoggerFactory factory, Log4NetProv
return factory;
}

#if !NETCOREAPP1_1
/// <summary>
/// Adds the log4net logging provider.
/// </summary>
Expand Down Expand Up @@ -96,6 +95,5 @@ public static ILoggingBuilder AddLog4Net(this ILoggingBuilder builder, Log4NetPr
builder.Services.AddSingleton<ILoggerProvider>(new Log4NetProvider(options));
return builder;
}
#endif
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ namespace Microsoft.Extensions.Logging
/// </summary>
public class Log4NetLogger : ILogger
{
private readonly IExternalScopeProvider externalScopeProvider;

/// <summary>
/// The log.
/// </summary>
Expand All @@ -24,9 +26,10 @@ public class Log4NetLogger : ILogger
/// Initializes a new instance of the <see cref="Log4NetLogger"/> class.
/// </summary>
/// <param name="options">The log4net provider options.</param>
public Log4NetLogger(Log4NetProviderOptions options)
public Log4NetLogger(Log4NetProviderOptions options, IExternalScopeProvider externalScopeProvider)
{
this.options = options ?? throw new ArgumentNullException(nameof(options));
this.externalScopeProvider = externalScopeProvider ?? throw new ArgumentNullException(nameof(externalScopeProvider));
this.logger = LogManager.GetLogger(options.LoggerRepository, options.Name).Logger;
}

Expand All @@ -42,6 +45,7 @@ public string Name
/// </summary>
internal Log4NetProviderOptions Options => this.options;


/// <summary>
/// Begins a logical operation scope.
/// </summary>
Expand All @@ -51,7 +55,7 @@ public string Name
/// An IDisposable that ends the logical operation scope on dispose.
/// </returns>
public IDisposable BeginScope<TState>(TState state)
=> options.ScopeFactory?.BeginScope(state);
=> externalScopeProvider.Push(state);

/// <summary>
/// Determines whether the logging level is enabled.
Expand Down Expand Up @@ -97,26 +101,18 @@ public void Log<TState>(
return;
}

var message = PrepareMessage(logLevel, eventId, state, exception, formatter);
LogMessage(message);
}
EnsureValidFormatter(formatter);

private void LogMessage<TState>(MessageCandidate<TState> candidate)
{
LoggingEvent loggingEvent = options.LoggingEventFactory.CreateLoggingEvent(candidate, logger, options);
var candidate = new MessageCandidate<TState>(logLevel, eventId, state, exception, formatter);

LoggingEvent loggingEvent = options.LoggingEventFactory.CreateLoggingEvent(in candidate, logger, options, externalScopeProvider);

if (loggingEvent == null)
return;

this.logger.Log(loggingEvent);
}

private static MessageCandidate<TState> PrepareMessage<TState>(LogLevel logLevel, EventId eventId, TState state, Exception exception, Func<TState, Exception, string> formatter)
{
EnsureValidFormatter(formatter);
return new MessageCandidate<TState>(logLevel, eventId, state, exception, formatter);
}

private static void EnsureValidFormatter<TState>(Func<TState, Exception, string> formatter)
{
if (formatter == null)
Expand Down
Loading

0 comments on commit a7f9087

Please sign in to comment.