-
Notifications
You must be signed in to change notification settings - Fork 129
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #162 from skomis-mm/filterswitch
LoggingFilterSwitch support
- Loading branch information
Showing
9 changed files
with
194 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
49 changes: 49 additions & 0 deletions
49
src/Serilog.Settings.Configuration/Settings/Configuration/LoggingFilterSwitchProxy.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
using System; | ||
|
||
namespace Serilog.Settings.Configuration | ||
{ | ||
class LoggingFilterSwitchProxy | ||
{ | ||
readonly Action<string> _setProxy; | ||
readonly Func<string> _getProxy; | ||
|
||
LoggingFilterSwitchProxy(object realSwitch) | ||
{ | ||
RealSwitch = realSwitch ?? throw new ArgumentNullException(nameof(realSwitch)); | ||
|
||
var expressionProperty = realSwitch.GetType().GetProperty("Expression"); | ||
|
||
_setProxy = (Action<string>)Delegate.CreateDelegate( | ||
typeof(Action<string>), | ||
realSwitch, | ||
expressionProperty.GetSetMethod()); | ||
|
||
_getProxy = (Func<string>)Delegate.CreateDelegate( | ||
typeof(Func<string>), | ||
realSwitch, | ||
expressionProperty.GetGetMethod()); | ||
} | ||
|
||
public object RealSwitch { get; } | ||
|
||
public string Expression | ||
{ | ||
get => _getProxy(); | ||
set => _setProxy(value); | ||
} | ||
|
||
public static LoggingFilterSwitchProxy Create(string expression = null) | ||
{ | ||
var filterSwitchType = | ||
Type.GetType("Serilog.Expressions.LoggingFilterSwitch, Serilog.Expressions") ?? | ||
Type.GetType("Serilog.Filters.Expressions.LoggingFilterSwitch, Serilog.Filters.Expressions"); | ||
|
||
if (filterSwitchType is null) | ||
{ | ||
return null; | ||
} | ||
|
||
return new LoggingFilterSwitchProxy(Activator.CreateInstance(filterSwitchType, expression)); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters