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
Extend support for static accessor to any type (not only interfaces or abstract classes) #1203
Comments
Hi Brandon, when implementing the static accessor features we kind of locked it down on purpose to avoid possible side effects, see conversation here : #1064 (comment) . I think this would offer a workaround for cases where the configuration cannot easily be expressed via the @serilog/reviewers-core any opinion on this one ? Also, there are also discussions about how to support |
Hi Thibaud, In the meantime, we cloned the extension methods used by the |
Any later thoughts on this? It seems on the surface that it would be a reasonable addition, especially in the context of things like I guess the question is how much effort is required and how robust the results might be. |
I think it's fair to relax a bit the initial rule, and allow access to static properties and fields of any type as long as it matches the config method signature. The general idea being that given a configuration that accepts a parameter named <?xml version="1.0" encoding="utf-8"?>
<configuration>
<appSettings>
...
<add key="serilog:write-to:Method.foo" value="MyNamespace.MyClass::MyCustomFoo, MyAssembly" />
</appSettings> Related to : #1057 If someone feels like issuing a PR, that would be great :) |
I'm working through open issues and closing most of those that have no activity in the past 12 months as If you believe that this issue still needs attention, please feel free to comment here. Thanks! |
A few questions before you begin:
Does this issue relate to a new feature or an existing bug?
What version of Serilog is affected? Please list the related NuGet package.
N/A. This is a new feature.
Please describe the current behavior?
Given a Serilog setup like the following:
And app.config:
On startup, Serilog will fail to convert the
string
"ExtremeValueInc.RollbarUtils::Transform"
into typeAction<Payload>
. The SettingValueConversions class is unable to find a suitable method for converting this value and defaults toConvert.ChangeType(value, toType)
Please describe the expected behavior?
The expected behavior is Serilog should widen the following conditional to allow
Delegate
s andAction
s types to be retrieved from properties and fields:https://github.com/serilog/serilog/blob/dev/src/Serilog/Settings/KeyValuePairs/SettingValueConversions.cs#L61
The code that flows within that
if
statement would appear to already be ready to handleDelegate
andAction
types.To be honest, it would appear to me that the statement condition is not appropriate for many conditions. If we have a
value
that has been found to map to a method/field within a class in a namespace, we should invoke it as long as the return type matches that of theapp.config
appsettings
value
?This is to say, if
TryParseStaticMemberAccessor
successfully parses thevalue
, and the return type of the found method matches thetoType
, we should invoke it.The text was updated successfully, but these errors were encountered: