diff --git a/.github/workflows/build-test-linux.yml b/.github/workflows/build-test-linux.yml new file mode 100644 index 0000000000..37880ad8bf --- /dev/null +++ b/.github/workflows/build-test-linux.yml @@ -0,0 +1,34 @@ +name: Build and test on linux + +on: + workflow_call: + +jobs: + build: + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v3 + + # Building requires an up-to-date .NET SDK. + - name: Setup dotnet + uses: actions/setup-dotnet@v3 + with: + dotnet-version: | + 6.0.x + 7.0.x + + # Restore and build + - name: Restore dependencies + run: dotnet restore + - name: Build Nuget Versions + run: dotnet build ./tools/Explicit.NuGet.Versions/Explicit.NuGet.Versions.sln + - name: Build Release + run: dotnet build Castle.Windsor.sln -c Release + + # Run tests for linux + - name: Test on .NET 6.0 + run: | + dotnet test src/Castle.Windsor.Tests -c Release -f net6.0 --no-build --no-restore -l "console;verbosity=detailed" + dotnet test src/Castle.Facilities.AspNetCore.Tests -c Release -f net6.0 --no-build --no-restore -l "console;verbosity=detailed" + dotnet test src/Castle.Windsor.Extensions.DependencyInjection.Tests -c Release -f net6.0 --no-build --no-restore -l "console;verbosity=detailed" diff --git a/.github/workflows/build-test-win.yml b/.github/workflows/build-test-win.yml new file mode 100644 index 0000000000..94391a0b93 --- /dev/null +++ b/.github/workflows/build-test-win.yml @@ -0,0 +1,34 @@ +name: Build and test on Windows + +on: + workflow_call: + +jobs: + build: + runs-on: windows-latest + + steps: + - uses: actions/checkout@v3 + + # Building requires an up-to-date .NET SDK. + - name: Setup dotnet + uses: actions/setup-dotnet@v3 + with: + dotnet-version: | + 6.0.x + 7.0.x + + # Restore and build + - name: Restore dependencies + run: dotnet restore + - name: Build Release + run: dotnet build Castle.Windsor.sln -c Release + + # Run tests on windows + - name: Test on .NET Framework 4.6.2 (Windows only) + run: | + dotnet test src/Castle.Windsor.Tests -c Release -f net462 --no-build --no-restore -l "console;verbosity=detailed" + dotnet test src/Castle.Facilities.AspNet.Mvc.Tests -c Release -f net462 --no-build --no-restore -l "console;verbosity=detailed" + dotnet test src/Castle.Facilities.AspNet.SystemWeb.Tests -c Release -f net462 --no-build --no-restore -l "console;verbosity=detailed" + dotnet test src/Castle.Facilities.AspNet.WebApi.Tests -c Release -f net462 --no-build --no-restore -l "console;verbosity=detailed" + dotnet test src/Castle.Facilities.WcfIntegration.Tests -c Release -f net462 --no-build --no-restore -l "console;verbosity=detailed" \ No newline at end of file diff --git a/.github/workflows/dotnet-release.yml b/.github/workflows/dotnet-release.yml new file mode 100644 index 0000000000..1269a95389 --- /dev/null +++ b/.github/workflows/dotnet-release.yml @@ -0,0 +1,43 @@ +name: .NET Release + +on: + push: + tags: + - 'v*.*.*' + +jobs: + build-lin: + name: Build and test Linux + uses: ./.github/workflows/build-test-linux.yml + + build-win: + name: Build and test on Windows + uses: ./.github/workflows/build-test-win.yml + + deploy: + needs: [build-lin, build-win] + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + + # Building requires an up-to-date .NET SDK. + - name: Setup dotnet + uses: actions/setup-dotnet@v3 + with: + dotnet-version: | + 6.0.x + 7.0.x + + - name: Restore dependencies + run: dotnet restore + - name: Get the version + id: get_version + run: echo ::set-output name=VERSION::$(echo $GITHUB_REF | cut -d / -f 3 | cut -d "v" -f 2) + + - name: Build + run: dotnet build Castle.Windsor.sln -c Release + - name: Pack + run: dotnet pack Castle.Windsor.sln -c Release -o artifacts -p:PackageVersion=${{ steps.get_version.outputs.VERSION }} + + - name: Push generated NuGet packages to GitHub Packages + run: dotnet nuget push "artifacts/*.nupkg" -k ${{secrets.GITHUB_TOKEN}} -s https://nuget.pkg.github.com/castleproject/index.json --skip-duplicate --no-symbols \ No newline at end of file diff --git a/.github/workflows/dotnet.yml b/.github/workflows/dotnet.yml new file mode 100644 index 0000000000..250e6544e6 --- /dev/null +++ b/.github/workflows/dotnet.yml @@ -0,0 +1,16 @@ +name: .NET CI + +on: + pull_request: + branches: [ master, main ] + paths-ignore: + - '**.md' + +jobs: + build-lin: + name: Build and test Linux + uses: ./.github/workflows/build-test-linux.yml + + build-win: + name: Build and test on Windows + uses: ./.github/workflows/build-test-win.yml diff --git a/CHANGELOG.md b/CHANGELOG.md index c5d4ab000c..3f7b008ea8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,17 +1,31 @@ # Castle Windsor Changelog -## Unreleased +## 6.0.0 (2023-07-20) -- Add fast lookup to check for already registered types. (@sqeezy, #618) -- Change target framework from .NET Standard 1.6 to 2.0 (@generik0, #572) -- Castle.Windsor.Extensions.DependencyInjection: Change Microsoft.Extensions.Logging dependencies to their abstract counterparts (@ikkentim, #626, #624) -- Add `net6.0` as a target (@Jevonius, #621) +Target Framework changes: +- Added `net6.0` (@Jevonius, #621) +- .NET Standard changed from 1.6 to 2.0 (@generik0, #572) +- .NET Framework changed from 4.5 to 4.6.2 + +Enhancements: +- Added fast lookup to check for already registered types (@sqeezy, #618) +- `Castle.Windsor.Extensions.DependencyInjection`: Change `Microsoft.Extensions.Logging` dependencies to their abstract counterparts (@ikkentim, #626, #624) Bugfixes: -- Castle.Windsor.Extensions.DependencyInjection: support parallel containers (@rvdginste, @generik0, #563, #577) +- `Castle.Windsor.Extensions.DependencyInjection`: support parallel containers (@rvdginste, @generik0, #563, #577) Breaking Changes: -- Microsoft.Extensions.Hosting related methods have been removed from the Castle.Windsor.Extensions.DependencyInjection package to the Castle.Windsor.Extensions.Hosting package (@ikkentim, #625, #628) +- Microsoft.Extensions.Hosting related methods have been moved from the `Castle.Windsor.Extensions.DependencyInjection` package to the `Castle.Windsor.Extensions.Hosting` package (@ikkentim, #625, #628) +- Obsolete APIs in `Castle.Facilities.Logging` have been removed. Extensions methods for built-in logging factories have been added, however `LogUsing` is still ideal. (@Jevonius, #636) + - Removed enum `Castle.Facilities.Logging.LoggerImplementation` + - Removed constructor `Castle.Facilities.Logging.LoggingFacility(LoggerImplementation loggingApi)` + - Removed constructor `Castle.Facilities.Logging.LoggingFacility(LoggerImplementation loggingApi, string configFile)` + - Removed constructor `Castle.Facilities.Logging.LoggingFacility(string customLoggerFactory, string configFile)` + - Removed method `Castle.Facilities.Logging.LoggingFacility.LogUsing(LoggerImplementation loggingApi)` + - Removed method `Castle.Facilities.Logging.LoggingFacility.UseLog4Net()` + - Removed method `Castle.Facilities.Logging.LoggingFacility.UseLog4Net(string configFile)` + - Removed method `Castle.Facilities.Logging.LoggingFacility.UseNLog()` + - Removed method `Castle.Facilities.Logging.LoggingFacility.UseNLog(string configFile)` ## 5.1.2 (2022-05-17) diff --git a/Castle.Windsor.sln b/Castle.Windsor.sln index b2e7f6ee36..d438cb73f5 100644 --- a/Castle.Windsor.sln +++ b/Castle.Windsor.sln @@ -1,7 +1,7 @@  Microsoft Visual Studio Solution File, Format Version 12.00 -# Visual Studio Version 16 -VisualStudioVersion = 16.0.30711.63 +# Visual Studio Version 17 +VisualStudioVersion = 17.7.33913.275 MinimumVisualStudioVersion = 10.0.40219.1 Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Castle.Windsor", "src\Castle.Windsor\Castle.Windsor.csproj", "{5F6A631E-8EB1-4BC1-826D-86D3059945B8}" EndProject @@ -20,9 +20,13 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Castle Build", "Castle Buil .gitattributes = .gitattributes .gitignore = .gitignore appveyor.yml = appveyor.yml + .github\workflows\build-test-linux.yml = .github\workflows\build-test-linux.yml + .github\workflows\build-test-win.yml = .github\workflows\build-test-win.yml build.cmd = build.cmd CHANGELOG.md = CHANGELOG.md CONTRIBUTING.md = CONTRIBUTING.md + .github\workflows\dotnet-release.yml = .github\workflows\dotnet-release.yml + .github\workflows\dotnet.yml = .github\workflows\dotnet.yml LICENSE = LICENSE README.md = README.md EndProjectSection diff --git a/README.md b/README.md index fffc48eced..9739ab5c48 100644 --- a/README.md +++ b/README.md @@ -12,7 +12,7 @@ See the [releases](https://github.com/castleproject/Windsor/releases). ## License -Castle Windsor is © 2004-2022 Castle Project. It is free software, and may be redistributed under the terms of the [Apache 2.0](http://opensource.org/licenses/Apache-2.0) license. +Castle Windsor is © 2004-2023 Castle Project. It is free software, and may be redistributed under the terms of the [Apache 2.0](http://opensource.org/licenses/Apache-2.0) license. ## NuGet Preview Feed @@ -30,20 +30,16 @@ The following conditional compilation symbols are currently defined for Windsor: Symbol | .NET 4.6.2 | .NET Standard / 6 ----------------------------------- | ------------------ | ------------------ -`CASTLE_SERVICES_LOGGING` | :white_check_mark: | :no_entry_sign: `FEATURE_APPDOMAIN` | :white_check_mark: | :no_entry_sign: `FEATURE_ASSEMBLIES` | :white_check_mark: | :no_entry_sign: -`FEATURE_EVENTLOG` | :white_check_mark: | :no_entry_sign: `FEATURE_PERFCOUNTERS`            | :white_check_mark: | :no_entry_sign: `FEATURE_REMOTING` | :white_check_mark: | :no_entry_sign: `FEATURE_SECURITY_PERMISSIONS` | :white_check_mark: | :no_entry_sign: `FEATURE_SERIALIZATION` | :white_check_mark: | :no_entry_sign: `FEATURE_SYSTEM_CONFIGURATION` | :white_check_mark: | :no_entry_sign: -* `CASTLE_SERVICES_LOGGING` - enables access to `Castle.Services.Logging.log4netIntegration` and `Castle.Services.Logging.NLogIntegration` in the logging facility. * `FEATURE_APPDOMAIN` - enables support for features that make use of an AppDomain in the host. * `FEATURE_ASSEMBLIES` - uses `AssemblyName.GetAssemblyName()` and `Assembly.LoadFile()`. -* `FEATURE_EVENTLOG` - uses Castle Core APIs that are based on the Windows Event Log. * `FEATURE_PERFCOUNTERS` - enables code that uses Windows Performance Counters. * `FEATURE_REMOTING` - supports remoting on various types including inheriting from `MarshalByRefObject`. * `FEATURE_SECURITY_PERMISSIONS` - enables the use of CAS and `Security[Critical|SafeCritical|Transparent]`. diff --git a/buildscripts/common.props b/buildscripts/common.props index 511e19191b..ca760b6ba2 100644 --- a/buildscripts/common.props +++ b/buildscripts/common.props @@ -36,7 +36,7 @@ - $(DefineConstants);FEATURE_PERFCOUNTERS;FEATURE_REMOTING;FEATURE_SECURITY_PERMISSIONS;FEATURE_SYSTEM_CONFIGURATION;FEATURE_SERIALIZATION;FEATURE_APPDOMAIN;FEATURE_CODEDOM;FEATURE_ASSEMBLIES;CASTLE_SERVICES_LOGGING;FEATURE_EVENTLOG + $(DefineConstants);FEATURE_PERFCOUNTERS;FEATURE_REMOTING;FEATURE_SECURITY_PERMISSIONS;FEATURE_SYSTEM_CONFIGURATION;FEATURE_SERIALIZATION;FEATURE_APPDOMAIN;FEATURE_CODEDOM;FEATURE_ASSEMBLIES diff --git a/docs/logging-facility.md b/docs/logging-facility.md index aa793e9cbe..b2d2f15e15 100644 --- a/docs/logging-facility.md +++ b/docs/logging-facility.md @@ -13,50 +13,65 @@ Castle Core [provides many logger abstraction implementations](https://github.co ## Registering the facility -:warning: **`LoggerImplementation` enum and the `loggingApi` XML property are deprecated:** Usage of `LogUsing` and `customLoggerFactory` are highly recommended even for Castle Core provided implementations. +### In code + +The recommended way of configuring the facility is using code. When specifying custom `ILoggerFactory` or `IExtendedLoggerFactory` you use the following generic overload: + +```csharp +container.AddFacility(f => f.LogUsing()); +``` + +For example, using the log4net logger factory with configuration stored in a `log4net.xml` file, the code would look like this: + +```csharp +container.AddFacility(f => f.LogUsing().WithConfig("log4net.xml")); +``` + +#### Built-in logging factories + +There are a few helper methods for built-in logging factories: +```csharp +// Null Logger +container.AddFacility(f => f.LogUsingNullLogger()); + +// Console Logger +container.AddFacility(f => f.LogUsingConsoleLogger()); + +// Diagnostics Logger +container.AddFacility(f => f.LogUsingDiagnosticsLogger()); + +// Trace Logger +container.AddFacility(f => f.LogUsingTraceLogger()); +``` ### Via XML Configuration -Logging facility exposes minimalistic configuration: +It is also possible to configure the facility via XML. For example the same configuration for log4net as above: ```xml + customLoggerFactory="Castle.Services.Logging.Log4netIntegration.Log4netFactory, Castle.Services.Logging.Log4netIntegration" + configFile="log4net.xml" /> ``` -For example to use log4net with logger configuration stored in `log4net.xml` file, you would configure the facility like this: +The full list of configuraation attributes is shown in the following example: ```xml + customLoggerFactory="" + configFile="" + loggerLevel="" + configuredExternally="" "/> ``` -### In code - -Recommended way of configuring the facility however, is using code. The facility exposes the same options like via XML. -For example the same configuration for log4net as above, from code would look like this: - -```csharp -container.AddFacility(f => f.LogUsing().WithConfig("log4net.xml")); -``` - -When specifying custom `ILoggerFactory` or `IExtendedLoggerFactory` you use the following generic overload: - -```csharp -container.AddFacility(f => f.LogUsing()); -``` - ## Best practices We recommend that you make logging optional on your components/services. This way you maximize the reusability. For example: @@ -66,17 +81,11 @@ using Castle.Core.Logging; public class CustomerService { - private ILogger logger = NullLogger.Instance; - public CustomerService() { } - public ILogger Logger - { - get { return logger; } - set { logger = value; } - } + public ILogger Logger { get; set; } = NullLogger.Instance; // ... } @@ -87,4 +96,4 @@ With the approach above, the logger field will never be null. Also, if the loggi ## Required Assemblies * `Castle.Facilities.Logging.dll` (bundled with Windsor) -* `Castle.Core.dll` (contains the `ILogger` and `ILoggerFactory`) +* `Castle.Core.dll` (contains the `ILogger` and `ILoggerFactory` interfaces; included as a dependency in the Windsor NuGet package) diff --git a/src/Castle.Facilities.AspNet.Mvc.Tests/Castle.Facilities.AspNet.Mvc.Tests.csproj b/src/Castle.Facilities.AspNet.Mvc.Tests/Castle.Facilities.AspNet.Mvc.Tests.csproj index 5512330dbe..55ee79c2e6 100644 --- a/src/Castle.Facilities.AspNet.Mvc.Tests/Castle.Facilities.AspNet.Mvc.Tests.csproj +++ b/src/Castle.Facilities.AspNet.Mvc.Tests/Castle.Facilities.AspNet.Mvc.Tests.csproj @@ -15,11 +15,11 @@ - + - + diff --git a/src/Castle.Facilities.AspNet.SystemWeb.Tests/Castle.Facilities.AspNet.SystemWeb.Tests.csproj b/src/Castle.Facilities.AspNet.SystemWeb.Tests/Castle.Facilities.AspNet.SystemWeb.Tests.csproj index fef2d0db98..9b287d5a60 100644 --- a/src/Castle.Facilities.AspNet.SystemWeb.Tests/Castle.Facilities.AspNet.SystemWeb.Tests.csproj +++ b/src/Castle.Facilities.AspNet.SystemWeb.Tests/Castle.Facilities.AspNet.SystemWeb.Tests.csproj @@ -19,10 +19,10 @@ - - - - + + + + diff --git a/src/Castle.Facilities.AspNet.WebApi.Tests/Castle.Facilities.AspNet.WebApi.Tests.csproj b/src/Castle.Facilities.AspNet.WebApi.Tests/Castle.Facilities.AspNet.WebApi.Tests.csproj index 4bf6854af9..5c4bb1721d 100644 --- a/src/Castle.Facilities.AspNet.WebApi.Tests/Castle.Facilities.AspNet.WebApi.Tests.csproj +++ b/src/Castle.Facilities.AspNet.WebApi.Tests/Castle.Facilities.AspNet.WebApi.Tests.csproj @@ -15,11 +15,11 @@ - + - + diff --git a/src/Castle.Facilities.AspNetCore.Tests/Castle.Facilities.AspNetCore.Tests.csproj b/src/Castle.Facilities.AspNetCore.Tests/Castle.Facilities.AspNetCore.Tests.csproj index 4efbaf31da..db42d80d66 100644 --- a/src/Castle.Facilities.AspNetCore.Tests/Castle.Facilities.AspNetCore.Tests.csproj +++ b/src/Castle.Facilities.AspNetCore.Tests/Castle.Facilities.AspNetCore.Tests.csproj @@ -1,13 +1,13 @@ - + - netcoreapp3.1 + net6.0 - + diff --git a/src/Castle.Facilities.AspNetCore/Castle.Facilities.AspNetCore.csproj b/src/Castle.Facilities.AspNetCore/Castle.Facilities.AspNetCore.csproj index 69d652dbda..d9e239c4ef 100644 --- a/src/Castle.Facilities.AspNetCore/Castle.Facilities.AspNetCore.csproj +++ b/src/Castle.Facilities.AspNetCore/Castle.Facilities.AspNetCore.csproj @@ -1,4 +1,4 @@ - + netstandard2.0 @@ -18,12 +18,12 @@ Castle.Facilities.AspNetCore - - - - - - + + + + + + diff --git a/src/Castle.Facilities.Logging/BuiltInLoggingFactoryExtensions.cs b/src/Castle.Facilities.Logging/BuiltInLoggingFactoryExtensions.cs new file mode 100644 index 0000000000..8a9f86ff8e --- /dev/null +++ b/src/Castle.Facilities.Logging/BuiltInLoggingFactoryExtensions.cs @@ -0,0 +1,30 @@ +// Copyright 2022 Castle Project - http://www.castleproject.org/ +// +// 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 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +namespace Castle.Facilities.Logging +{ + using Castle.Core.Logging; + + public static class BuiltInLoggingFactoryExtensions + { + public static LoggingFacility LogUsingNullLogger(this LoggingFacility loggingFacility) => loggingFacility.LogUsing(); + public static LoggingFacility LogUsingConsoleLogger(this LoggingFacility loggingFacility) => loggingFacility.LogUsing(); + +#if NET6_0_OR_GREATER + [System.Runtime.Versioning.SupportedOSPlatform("windows")] +#endif + public static LoggingFacility LogUsingDiagnosticsLogger(this LoggingFacility loggingFacility) => loggingFacility.LogUsing(); + public static LoggingFacility LogUsingTraceLogger(this LoggingFacility loggingFacility) => loggingFacility.LogUsing(); + } +} diff --git a/src/Castle.Facilities.Logging/LoggerImplementation.cs b/src/Castle.Facilities.Logging/LoggerImplementation.cs deleted file mode 100644 index 90b99a3ddb..0000000000 --- a/src/Castle.Facilities.Logging/LoggerImplementation.cs +++ /dev/null @@ -1,41 +0,0 @@ -// Copyright 2004-2017 Castle Project - http://www.castleproject.org/ -// -// 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 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -namespace Castle.Facilities.Logging -{ - using System; - - using Castle.Core.Logging; - - /// - /// The supported implementations. - /// - [Obsolete("A logger factory implementation type should be provided via LogUsing(), this will be removed in the future.")] - public enum LoggerImplementation - { - Custom, - Null, - Console, -#if FEATURE_EVENTLOG - Diagnostics, -#endif -#if CASTLE_SERVICES_LOGGING - NLog, - Log4net, - ExtendedNLog, - ExtendedLog4net, -#endif - Trace - } -} \ No newline at end of file diff --git a/src/Castle.Facilities.Logging/LoggingFacility.cs b/src/Castle.Facilities.Logging/LoggingFacility.cs index 02c228e5de..dbe868ce90 100644 --- a/src/Castle.Facilities.Logging/LoggingFacility.cs +++ b/src/Castle.Facilities.Logging/LoggingFacility.cs @@ -1,4 +1,4 @@ -// Copyright 2004-2017 Castle Project - http://www.castleproject.org/ +// Copyright 2004-2022 Castle Project - http://www.castleproject.org/ // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -12,8 +12,6 @@ // See the License for the specific language governing permissions and // limitations under the License. -#pragma warning disable CS0618 // Suppress LoggerImplementation is obsolete warning until removed - namespace Castle.Facilities.Logging { using System; @@ -32,34 +30,12 @@ namespace Castle.Facilities.Logging /// public class LoggingFacility : AbstractFacility { -#if CASTLE_SERVICES_LOGGING //Castle.Services.Logging.Log4netIntegration and Castle.Services.Logging.NLogIntegration are not available for .NET Standard - private static readonly String ExtendedLog4NetLoggerFactoryTypeName = - "Castle.Services.Logging.Log4netIntegration.ExtendedLog4netFactory," + - "Castle.Services.Logging.Log4netIntegration,Version=4.0.0.0, Culture=neutral," + - "PublicKeyToken=407dd0808d44fbdc"; - - private static readonly String ExtendedNLogLoggerFactoryTypeName = - "Castle.Services.Logging.NLogIntegration.ExtendedNLogFactory," + - "Castle.Services.Logging.NLogIntegration,Version=4.0.0.0, Culture=neutral," + - "PublicKeyToken=407dd0808d44fbdc"; - - private static readonly String Log4NetLoggerFactoryTypeName = - "Castle.Services.Logging.Log4netIntegration.Log4netFactory," + - "Castle.Services.Logging.Log4netIntegration,Version=4.0.0.0, Culture=neutral," + - "PublicKeyToken=407dd0808d44fbdc"; - - private static readonly String NLogLoggerFactoryTypeName = - "Castle.Services.Logging.NLogIntegration.NLogFactory," + - "Castle.Services.Logging.NLogIntegration,Version=4.0.0.0, Culture=neutral," + - "PublicKeyToken=407dd0808d44fbdc"; -#endif private readonly string customLoggerFactoryTypeName; private string configFileName; private ITypeConverter converter; - private LoggerImplementation? loggerImplementation; - private Type loggingFactoryType; + private Type loggerFactoryType; private LoggerLevel? loggerLevel; private ILoggerFactory loggerFactory; private string logName; @@ -72,73 +48,28 @@ public LoggingFacility() { } - /// - /// Initializes a new instance of the class. - /// - /// The LoggerImplementation that should be used - [Obsolete("A logger factory implementation type should be provided via LogUsing(), this will be removed in the future.")] - public LoggingFacility(LoggerImplementation loggingApi) : this(loggingApi, null) - { - } - - /// - /// Initializes a new instance of the class. - /// - /// The LoggerImplementation that should be used - /// The configuration file that should be used by the chosen LoggerImplementation - [Obsolete("A logger factory implementation type should be provided via LogUsing(), this will be removed in the future.")] - public LoggingFacility(LoggerImplementation loggingApi, string configFile) : this(loggingApi, null, configFile) - { - } - /// /// Initializes a new instance of the class using a custom LoggerImplementation /// - /// The configuration file that should be used by the chosen LoggerImplementation /// The type name of the type of the custom logger factory. - public LoggingFacility(string customLoggerFactory, string configFile) - : this(LoggerImplementation.Custom, customLoggerFactory, configFile) - { - } - - /// - /// Initializes a new instance of the class. - /// - /// The LoggerImplementation that should be used /// The configuration file that should be used by the chosen LoggerImplementation - /// The type name of the type of the custom logger factory. (only used when loggingApi is set to LoggerImplementation.Custom) - [Obsolete("A logger factory implementation type should be provided via LogUsing(), this will be removed in the future.")] - public LoggingFacility(LoggerImplementation loggingApi, string customLoggerFactory, string configFile) + public LoggingFacility(string customLoggerFactory, string configFile) { - loggerImplementation = loggingApi; customLoggerFactoryTypeName = customLoggerFactory; configFileName = configFile; } - [Obsolete("A logger factory implementation type should be provided via LogUsing(), this will be removed in the future.")] - public LoggingFacility LogUsing(LoggerImplementation loggingApi) - { - if (loggingApi == LoggerImplementation.Custom) - { - throw new FacilityException("To use custom logger use LogUsing() method."); - } - loggerImplementation = loggingApi; - return this; - } - public LoggingFacility LogUsing() where TLoggerFactory : ILoggerFactory { - loggerImplementation = LoggerImplementation.Custom; - loggingFactoryType = typeof(TLoggerFactory); + loggerFactoryType = typeof(TLoggerFactory); return this; } public LoggingFacility LogUsing(TLoggerFactory loggerFactory) where TLoggerFactory : ILoggerFactory { - loggerImplementation = LoggerImplementation.Custom; - loggingFactoryType = typeof(TLoggerFactory); + loggerFactoryType = typeof(TLoggerFactory); this.loggerFactory = loggerFactory; return this; } @@ -151,9 +82,7 @@ public LoggingFacility ConfiguredExternally() public LoggingFacility WithConfig(string configFile) { - if (configFile == null) throw new ArgumentNullException(nameof(configFile)); - - configFileName = configFile; + configFileName = configFile ?? throw new ArgumentNullException(nameof(configFile)); return this; } @@ -169,32 +98,6 @@ public LoggingFacility ToLog(string name) return this; } -#if CASTLE_SERVICES_LOGGING - [Obsolete("A logger factory implementation type should be provided via LogUsing(), this will be removed in the future.")] - public LoggingFacility UseLog4Net() - { - return LogUsing(LoggerImplementation.Log4net); - } - - [Obsolete("A logger factory implementation type should be provided via LogUsing(), this will be removed in the future.")] - public LoggingFacility UseLog4Net(string configFile) - { - return UseLog4Net().WithConfig(configFile); - } - - [Obsolete("A logger factory implementation type should be provided via LogUsing(), this will be removed in the future.")] - public LoggingFacility UseNLog() - { - return LogUsing(LoggerImplementation.NLog); - } - - [Obsolete("A logger factory implementation type should be provided via LogUsing(), this will be removed in the future.")] - public LoggingFacility UseNLog(string configFile) - { - return LogUsing(LoggerImplementation.NLog).WithConfig(configFile); - } -#endif - #if FEATURE_SYSTEM_CONFIGURATION /// /// loads configuration from current AppDomain's config file (aka web.config/app.config) @@ -212,30 +115,54 @@ protected override void Init() SetUpTypeConverter(); if (loggerFactory == null) { - loggerFactory = ReadConfigurationAndCreateLoggerFactory(); + ReadConfigurationAndCreateLoggerFactory(); } RegisterLoggerFactory(loggerFactory); RegisterDefaultILogger(loggerFactory); RegisterSubResolver(loggerFactory); } - private ILoggerFactory CreateProperLoggerFactory(LoggerImplementation loggerApi) + private void ReadConfigurationAndCreateLoggerFactory() { - var loggerFactoryType = GetLoggingFactoryType(loggerApi); - Debug.Assert(loggerFactoryType != null, "loggerFactoryType != null"); + if (loggerFactoryType == null) + { + loggerFactoryType = ReadCustomLoggerType(); + } + EnsureIsValidLoggerFactoryType(); + CreateProperLoggerFactory(); + } - var ctorArgs = GetLoggingFactoryArguments(loggerFactoryType); - return loggerFactoryType.CreateInstance(ctorArgs); + private Type ReadCustomLoggerType() + { + if (FacilityConfig != null) + { + var customLoggerType = FacilityConfig.Attributes["customLoggerFactory"]; + if (string.IsNullOrEmpty(customLoggerType) == false) + { + return converter.PerformConversion(customLoggerType); + } + } + if (customLoggerFactoryTypeName != null) + { + return converter.PerformConversion(customLoggerFactoryTypeName); + } + return typeof(NullLogFactory); } - private Type EnsureIsValidLoggerFactoryType(Type loggerFactoryType) + private void EnsureIsValidLoggerFactoryType() { - if (loggerFactoryType.Is() || loggerFactoryType.Is()) + if (!loggerFactoryType.Is()) { - return loggerFactoryType; + throw new FacilityException($"The specified type '{loggerFactoryType}' does not implement ILoggerFactory."); } - throw new FacilityException("The specified type '" + loggerFactoryType + - "' does not implement either ILoggerFactory or IExtendedLoggerFactory."); + } + + private void CreateProperLoggerFactory() + { + Debug.Assert(loggerFactoryType != null, "loggerFactoryType != null"); + + var ctorArgs = GetLoggingFactoryArguments(); + loggerFactory = loggerFactoryType.CreateInstance(ctorArgs); } private string GetConfigFile() @@ -252,12 +179,7 @@ private string GetConfigFile() return null; } - private Type GetCustomLoggerType() - { - return EnsureIsValidLoggerFactoryType(ReadCustomLoggerType()); - } - - private object[] GetLoggingFactoryArguments(Type loggerFactoryType) + private object[] GetLoggingFactoryArguments() { const BindingFlags flags = BindingFlags.Instance | BindingFlags.Public; @@ -294,7 +216,7 @@ private object[] GetLoggingFactoryArguments(Type loggerFactoryType) { return new object[0]; } - throw new FacilityException("No support constructor found for logging type " + loggerFactoryType); + throw new FacilityException($"No support constructor found for logging type '{loggerFactoryType}'"); } private bool IsConfiguredExternally() @@ -331,84 +253,6 @@ private bool IsConfiguredExternally() return null; } - private Type GetLoggingFactoryType(LoggerImplementation loggerApi) - { - switch (loggerApi) - { - case LoggerImplementation.Custom: - return GetCustomLoggerType(); - case LoggerImplementation.Null: - return typeof(NullLogFactory); - case LoggerImplementation.Console: - return typeof(ConsoleFactory); -#if FEATURE_EVENTLOG //has dependency on Castle.Core.Logging.DiagnosticsLoggerFactory - case LoggerImplementation.Diagnostics: - return typeof(DiagnosticsLoggerFactory); -#endif - case LoggerImplementation.Trace: - return typeof(TraceLoggerFactory); -#if CASTLE_SERVICES_LOGGING - case LoggerImplementation.NLog: - return converter.PerformConversion(NLogLoggerFactoryTypeName); - case LoggerImplementation.Log4net: - return converter.PerformConversion(Log4NetLoggerFactoryTypeName); - case LoggerImplementation.ExtendedLog4net: - return converter.PerformConversion(ExtendedLog4NetLoggerFactoryTypeName); - case LoggerImplementation.ExtendedNLog: - return converter.PerformConversion(ExtendedNLogLoggerFactoryTypeName); -#endif - default: - { - throw new FacilityException("An invalid loggingApi was specified: " + loggerApi); - } - } - } - - private ILoggerFactory ReadConfigurationAndCreateLoggerFactory() - { - var logApi = ReadLoggingApi(); - var loggerFactory = CreateProperLoggerFactory(logApi); - return loggerFactory; - } - - private Type ReadCustomLoggerType() - { - if (FacilityConfig != null) - { - var customLoggerType = FacilityConfig.Attributes["customLoggerFactory"]; - if (string.IsNullOrEmpty(customLoggerType) == false) - { - return converter.PerformConversion(customLoggerType); - } - } - if (customLoggerFactoryTypeName != null) - { - return converter.PerformConversion(customLoggerFactoryTypeName); - } - if (loggingFactoryType != null) - { - return loggingFactoryType; - } - var message = "If you specify loggingApi='custom' " + - "then you must use the attribute customLoggerFactory to inform the " + - "type name of the custom logger factory"; - - throw new FacilityException(message); - } - - private LoggerImplementation ReadLoggingApi() - { - if (FacilityConfig != null) - { - var configLoggingApi = FacilityConfig.Attributes["loggingApi"]; - if (string.IsNullOrEmpty(configLoggingApi) == false) - { - return converter.PerformConversion(configLoggingApi); - } - } - return loggerImplementation.GetValueOrDefault(LoggerImplementation.Console); - } - private void RegisterDefaultILogger(ILoggerFactory factory) { if (factory is IExtendedLoggerFactory) @@ -454,5 +298,3 @@ private void SetUpTypeConverter() } } } - -#pragma warning restore CS0618 // Suppress LoggerImplementation is obsolete warning until removed diff --git a/src/Castle.Facilities.WcfIntegration.Tests/Castle.Facilities.WcfIntegration.Tests.csproj b/src/Castle.Facilities.WcfIntegration.Tests/Castle.Facilities.WcfIntegration.Tests.csproj index 3d0cf68e78..74829b457c 100644 --- a/src/Castle.Facilities.WcfIntegration.Tests/Castle.Facilities.WcfIntegration.Tests.csproj +++ b/src/Castle.Facilities.WcfIntegration.Tests/Castle.Facilities.WcfIntegration.Tests.csproj @@ -13,9 +13,8 @@ - - + diff --git a/src/Castle.Windsor.Tests/Castle.Windsor.Tests.csproj b/src/Castle.Windsor.Tests/Castle.Windsor.Tests.csproj index 4a9a1b29fa..f0e9932ea1 100644 --- a/src/Castle.Windsor.Tests/Castle.Windsor.Tests.csproj +++ b/src/Castle.Windsor.Tests/Castle.Windsor.Tests.csproj @@ -1,7 +1,7 @@  - net462;netcoreapp3.1;net6.0 + net462;netcoreapp3.1;net6.0 @@ -44,17 +44,17 @@ + + - + - - - + @@ -69,7 +69,7 @@ - + $(DefineConstants);FEATURE_THREADABORT;FEATURE_WPF;FEATURE_CONSOLETRACELISTENER diff --git a/src/Castle.Windsor.Tests/Config/ConfigurationTestCase.cs b/src/Castle.Windsor.Tests/Config/ConfigurationTestCase.cs index e8a6858775..83b613b5c7 100644 --- a/src/Castle.Windsor.Tests/Config/ConfigurationTestCase.cs +++ b/src/Castle.Windsor.Tests/Config/ConfigurationTestCase.cs @@ -15,7 +15,7 @@ namespace Castle.MicroKernel.Tests.Configuration { using System.Collections.Generic; - + using System.IO; using Castle.Core; using Castle.Core.Configuration; using Castle.Core.Resource; @@ -218,7 +218,8 @@ public void ShouldNotThrowCircularDependencyException() [Test] public void Can_properly_populate_array_dependency_from_xml_config_when_registering_by_convention() { - Container.Install(Configuration.FromXmlFile("config\\ComponentWithArrayDependency.config")) + var path = Path.Combine("Config", "ComponentWithArrayDependency.config"); + Container.Install(Configuration.FromXmlFile(path)) .Register(Component.For().ImplementedBy().Named("componentWithArrayDependency")); Container.Register( Classes.FromAssembly(GetCurrentAssembly()).Pick().WithServiceFirstInterface()); diff --git a/src/Castle.Windsor.Tests/LoggingFacility/BaseTest.cs b/src/Castle.Windsor.Tests/LoggingFacility/BaseTest.cs index 152be5c4ad..12616e4471 100644 --- a/src/Castle.Windsor.Tests/LoggingFacility/BaseTest.cs +++ b/src/Castle.Windsor.Tests/LoggingFacility/BaseTest.cs @@ -1,4 +1,4 @@ -// Copyright 2004-2017 Castle Project - http://www.castleproject.org/ +// Copyright 2004-2022 Castle Project - http://www.castleproject.org/ // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -16,11 +16,10 @@ namespace Castle.Facilities.Logging.Tests { using Castle.Core.Logging; using Castle.MicroKernel.SubSystems.Configuration; -#if CASTLE_SERVICES_LOGGING using Castle.Services.Logging.Log4netIntegration; using Castle.Services.Logging.NLogIntegration; -#endif using Castle.Windsor; + using System.IO; /// /// Summary description for BaseTest. @@ -41,18 +40,16 @@ protected virtual IWindsorContainer CreateConfiguredContainer() protected string GetConfigFile() where TLoggerFactory : ILoggerFactory { -#if CASTLE_SERVICES_LOGGING if (typeof(TLoggerFactory) == typeof(Log4netFactory) || typeof(TLoggerFactory) == typeof(ExtendedLog4netFactory)) { - return "LoggingFacility\\log4net.facilities.test.config"; + return Path.Combine("LoggingFacility", "log4net.facilities.test.config"); } if (typeof(TLoggerFactory) == typeof(NLogFactory) || typeof(TLoggerFactory) == typeof(ExtendedNLogFactory)) { - return "LoggingFacility\\NLog.facilities.test.config"; + return Path.Combine("LoggingFacility", "NLog.facilities.test.config"); } -#endif return string.Empty; } } diff --git a/src/Castle.Windsor.Tests/LoggingFacility/Classes/CustomLog4NetFactory.cs b/src/Castle.Windsor.Tests/LoggingFacility/Classes/CustomLog4NetFactory.cs index 64bd4dcba8..cc44eefe0b 100644 --- a/src/Castle.Windsor.Tests/LoggingFacility/Classes/CustomLog4NetFactory.cs +++ b/src/Castle.Windsor.Tests/LoggingFacility/Classes/CustomLog4NetFactory.cs @@ -1,4 +1,4 @@ -// Copyright 2004-2011 Castle Project - http://www.castleproject.org/ +// Copyright 2004-2022 Castle Project - http://www.castleproject.org/ // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -12,8 +12,6 @@ // See the License for the specific language governing permissions and // limitations under the License. - -#if CASTLE_SERVICES_LOGGING namespace CastleTests.LoggingFacility.Tests.Classes { using System; @@ -43,4 +41,3 @@ public override ILogger Create(String name, LoggerLevel level) } } } -#endif \ No newline at end of file diff --git a/src/Castle.Windsor.Tests/LoggingFacility/CustomFacilityTests.cs b/src/Castle.Windsor.Tests/LoggingFacility/CustomFacilityTests.cs index 031fde6cd8..fdb6d00df6 100644 --- a/src/Castle.Windsor.Tests/LoggingFacility/CustomFacilityTests.cs +++ b/src/Castle.Windsor.Tests/LoggingFacility/CustomFacilityTests.cs @@ -1,4 +1,4 @@ -// Copyright 2004-2011 Castle Project - http://www.castleproject.org/ +// Copyright 2004-2022 Castle Project - http://www.castleproject.org/ // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -12,7 +12,6 @@ // See the License for the specific language governing permissions and // limitations under the License. -#if CASTLE_SERVICES_LOGGING namespace CastleTests.LoggingFacility { using Castle.Core.Logging; @@ -40,8 +39,7 @@ public void ReadCustomFacilityConfigFromXML() string.Format( @" - @@ -54,4 +52,3 @@ public void ReadCustomFacilityConfigFromXML() } } } -#endif \ No newline at end of file diff --git a/src/Castle.Windsor.Tests/LoggingFacility/ExtendedLog4NetFacilityTestCase.cs b/src/Castle.Windsor.Tests/LoggingFacility/ExtendedLog4NetFacilityTestCase.cs index fae9c008ac..650330cf2f 100644 --- a/src/Castle.Windsor.Tests/LoggingFacility/ExtendedLog4NetFacilityTestCase.cs +++ b/src/Castle.Windsor.Tests/LoggingFacility/ExtendedLog4NetFacilityTestCase.cs @@ -1,4 +1,4 @@ -// Copyright 2004-2017 Castle Project - http://www.castleproject.org/ +// Copyright 2004-2022 Castle Project - http://www.castleproject.org/ // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -12,7 +12,6 @@ // See the License for the specific language governing permissions and // limitations under the License. -#if CASTLE_SERVICES_LOGGING namespace Castle.Facilities.Logging.Tests { using System; @@ -101,4 +100,3 @@ public void ContextTest() } } } -#endif diff --git a/src/Castle.Windsor.Tests/LoggingFacility/ExtendedNLogFacilityTests.cs b/src/Castle.Windsor.Tests/LoggingFacility/ExtendedNLogFacilityTests.cs index c7ed0d55e9..14bc7c7090 100644 --- a/src/Castle.Windsor.Tests/LoggingFacility/ExtendedNLogFacilityTests.cs +++ b/src/Castle.Windsor.Tests/LoggingFacility/ExtendedNLogFacilityTests.cs @@ -1,4 +1,4 @@ -// Copyright 2004-2017 Castle Project - http://www.castleproject.org/ +// Copyright 2004-2022 Castle Project - http://www.castleproject.org/ // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -12,7 +12,6 @@ // See the License for the specific language governing permissions and // limitations under the License. -#if CASTLE_SERVICES_LOGGING namespace Castle.Facilities.Logging.Tests { using System; @@ -87,4 +86,3 @@ public void ContextTest() } } } -#endif diff --git a/src/Castle.Windsor.Tests/LoggingFacility/Log4NetFacilityLognameOverrideTests.cs b/src/Castle.Windsor.Tests/LoggingFacility/Log4NetFacilityLognameOverrideTests.cs index ffdbd63a86..4a897132df 100644 --- a/src/Castle.Windsor.Tests/LoggingFacility/Log4NetFacilityLognameOverrideTests.cs +++ b/src/Castle.Windsor.Tests/LoggingFacility/Log4NetFacilityLognameOverrideTests.cs @@ -1,4 +1,4 @@ -// Copyright 2004-2017 Castle Project - http://www.castleproject.org/ +// Copyright 2004-2022 Castle Project - http://www.castleproject.org/ // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -12,7 +12,6 @@ // See the License for the specific language governing permissions and // limitations under the License. -#if CASTLE_SERVICES_LOGGING namespace Castle.Facilities.Logging.Tests { using System; @@ -65,4 +64,3 @@ public void OverrideTest() } } } -#endif \ No newline at end of file diff --git a/src/Castle.Windsor.Tests/LoggingFacility/Log4NetFacilityTests.cs b/src/Castle.Windsor.Tests/LoggingFacility/Log4NetFacilityTests.cs index a286c0f1bb..aabb6ba32b 100644 --- a/src/Castle.Windsor.Tests/LoggingFacility/Log4NetFacilityTests.cs +++ b/src/Castle.Windsor.Tests/LoggingFacility/Log4NetFacilityTests.cs @@ -1,4 +1,4 @@ -// Copyright 2004-2017 Castle Project - http://www.castleproject.org/ +// Copyright 2004-2022 Castle Project - http://www.castleproject.org/ // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -12,7 +12,6 @@ // See the License for the specific language governing permissions and // limitations under the License. -#if CASTLE_SERVICES_LOGGING namespace Castle.Facilities.Logging.Tests { using System; @@ -66,4 +65,3 @@ public void SimpleTest() } } } -#endif diff --git a/src/Castle.Windsor.Tests/LoggingFacility/NLogFacilityTests.cs b/src/Castle.Windsor.Tests/LoggingFacility/NLogFacilityTests.cs index e8f17412ee..d739f77248 100644 --- a/src/Castle.Windsor.Tests/LoggingFacility/NLogFacilityTests.cs +++ b/src/Castle.Windsor.Tests/LoggingFacility/NLogFacilityTests.cs @@ -1,4 +1,4 @@ -// Copyright 2004-2017 Castle Project - http://www.castleproject.org/ +// Copyright 2004-2022 Castle Project - http://www.castleproject.org/ // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -12,7 +12,6 @@ // See the License for the specific language governing permissions and // limitations under the License. -#if CASTLE_SERVICES_LOGGING namespace Castle.Facilities.Logging.Tests { using System; @@ -65,4 +64,3 @@ public void SimpleTest() } } } -#endif \ No newline at end of file