Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove obsolete code in Castle.Facilities.Logging #636

Merged
merged 5 commits into from
Jul 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ Bugfixes:

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)
- Obsolete components in Castle.Facilities.Logging have been removed. Extensions methods for built-in logging factories have been added. (@Jevonius, #616)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you list out the public APIs that have been removed like we do in Castle Core (https://github.com/castleproject/Core/blob/master/CHANGELOG.md#440-2019-04-05) so it makes it clear to upgraders and to enable search. You don't need every enum member, just the enum type name.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here are the removed classes and methods. Is anything else needed to merge this and create a release. I am happy to help get this out the door.

  • Removed class 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)

Expand Down
4 changes: 0 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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]`.
Expand Down
2 changes: 1 addition & 1 deletion buildscripts/common.props
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
</PropertyGroup>

<PropertyGroup Condition="'$(TargetFramework)'=='net462'">
<DefineConstants>$(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>
<DefineConstants>$(DefineConstants);FEATURE_PERFCOUNTERS;FEATURE_REMOTING;FEATURE_SECURITY_PERMISSIONS;FEATURE_SYSTEM_CONFIGURATION;FEATURE_SERIALIZATION;FEATURE_APPDOMAIN;FEATURE_CODEDOM;FEATURE_ASSEMBLIES</DefineConstants>
</PropertyGroup>

<ItemGroup>
Expand Down
71 changes: 40 additions & 31 deletions docs/logging-facility.md
Original file line number Diff line number Diff line change
Expand Up @@ -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<LoggingFacility>(f => f.LogUsing<CustomLoggerFactory>());
```

For example, using the log4net logger factory with configuration stored in a `log4net.xml` file, the code would look like this:

```csharp
container.AddFacility<LoggingFacility>(f => f.LogUsing<Log4netFactory>().WithConfig("log4net.xml"));
```

#### Built-in logging factories

There are a few helper methods for built-in logging factories:
```csharp
// Null Logger
container.AddFacility<LoggingFacility>(f => f.LogUsingNullLogger());

// Console Logger
container.AddFacility<LoggingFacility>(f => f.LogUsingConsoleLogger());

// Diagnostics Logger
container.AddFacility<LoggingFacility>(f => f.LogUsingDiagnosticsLogger());

// Trace Logger
container.AddFacility<LoggingFacility>(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
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<facility
type="Castle.Facilities.Logging.LoggingFacility, Castle.Facilities.Logging"
loggingApi="null|console|diagnostics|web|nlog|log4net|custom"
customLoggerFactory="type name that implements ILoggerFactory"
configFile="optional config file location" />
customLoggerFactory="Castle.Services.Logging.Log4netIntegration.Log4netFactory, Castle.Services.Logging.Log4netIntegration"
configFile="log4net.xml" />
</configuration>
```

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
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<facility
type="Castle.Facilities.Logging.LoggingFacility, Castle.Facilities.Logging"
loggingApi="log4net"
configFile="log4net.xml" />
customLoggerFactory="<type of factory>"
configFile="<path to configuration file (optional attribute)>"
loggerLevel="<the loggerLevel (optional attribute)>"
configuredExternally="<boolean value (optional attribute)>" "/>
</configuration>
```

### 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<LoggingFacility>(f => f.LogUsing<Log4netFactory>().WithConfig("log4net.xml"));
```

When specifying custom `ILoggerFactory` or `IExtendedLoggerFactory` you use the following generic overload:

```csharp
container.AddFacility<LoggingFacility>(f => f.LogUsing<CustomLoggerFactory>());
```

## Best practices

We recommend that you make logging optional on your components/services. This way you maximize the reusability. For example:
Expand All @@ -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;

// ...
}
Expand All @@ -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)
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@

<ItemGroup>
<PackageReference Include="Microsoft.AspNet.Mvc" Version="5.2.3" />
<PackageReference Include="Microsoft.Web.Infrastructure" Version="1.0.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.3.2" />
<PackageReference Include="Microsoft.TestPlatform.ObjectModel" Version="11.0.0" />
<PackageReference Include="Microsoft.Web.Infrastructure" Version="1.0.0" />
<PackageReference Include="NUnit" Version="3.13.3" />
<PackageReference Include="NUnit3TestAdapter" Version="4.2.1" />
</ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="NUnit" Version="3.13.3" />
<PackageReference Include="NUnit3TestAdapter" Version="4.2.1" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.3.2" />
<PackageReference Include="Microsoft.TestPlatform.ObjectModel" Version="17.3.2" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.3.2" />
<PackageReference Include="Microsoft.TestPlatform.ObjectModel" Version="11.0.0" />
jonorossi marked this conversation as resolved.
Show resolved Hide resolved
<PackageReference Include="NUnit" Version="3.13.3" />
<PackageReference Include="NUnit3TestAdapter" Version="4.2.1" />
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@

<ItemGroup>
<PackageReference Include="Microsoft.AspNet.WebApi" Version="5.2.3" />
<PackageReference Include="Microsoft.Web.Infrastructure" Version="1.0.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.3.2" />
<PackageReference Include="Microsoft.TestPlatform.ObjectModel" Version="11.0.0" />
<PackageReference Include="Microsoft.Web.Infrastructure" Version="1.0.0" />
<PackageReference Include="NUnit" Version="3.13.3" />
<PackageReference Include="NUnit3TestAdapter" Version="4.2.1" />
</ItemGroup>
Expand Down
30 changes: 30 additions & 0 deletions src/Castle.Facilities.Logging/BuiltInLoggingFactoryExtensions.cs
Original file line number Diff line number Diff line change
@@ -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<NullLogFactory>();
public static LoggingFacility LogUsingConsoleLogger(this LoggingFacility loggingFacility) => loggingFacility.LogUsing<ConsoleFactory>();

#if NET6_0_OR_GREATER
[System.Runtime.Versioning.SupportedOSPlatform("windows")]
#endif
public static LoggingFacility LogUsingDiagnosticsLogger(this LoggingFacility loggingFacility) => loggingFacility.LogUsing<DiagnosticsLoggerFactory>();
public static LoggingFacility LogUsingTraceLogger(this LoggingFacility loggingFacility) => loggingFacility.LogUsing<TraceLoggerFactory>();
}
}
41 changes: 0 additions & 41 deletions src/Castle.Facilities.Logging/LoggerImplementation.cs

This file was deleted.

Loading