-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
LoggingConfigurationParser - Added support for using assembly-name in type-name #4300
Conversation
e4e668c
to
cdbe308
Compare
@ThomasArdal Notice NLog will now attempt to extract Extension-Assembly-Name from the type-prefix. This means NLog will attempt to load assembly-name "elmah", when having forgotten to include <targets>
<target name="elmahio" type="elmah.io" apiKey="API_KEY" logId="LOG_ID"/>
</targets> And if one tries to make use of this feature with Elmah.io, then it fail to recognize that "elmah.io" is the symbol-name. But instead think that "io" is the symbol-name and "Elmah.Io.NLog.elmah" is the assembly-name: <targets>
<target name="elmahio" type="Elmah.Io.NLog.elmah.io" apiKey="API_KEY" logId="LOG_ID"/>
</targets> Btw. funny the Elmah.io with NLog has no examples or documentation of how to setup NLog. Maybe include a link to the Docs (or nuget-package) |
21f8e9b
to
ecd9173
Compare
@snakefoot If I remember corretly, the [Target("elmah.io")] Would it change anything if the target is named |
@ThomasArdal Yes instead of this: [Target("elmah.io")]
public class ElmahIoTarget : AsyncTaskTarget Then with NLog 5.0 it is possible to do this: [Target("elmah.io")]
[Target("elmah-io")]
[Target("ElmahIo")]
public class ElmahIoTarget : AsyncTaskTarget |
@snakefoot That's nice. Will add that in time when we move the dependency to 5.0 for sure. Maybe you should consider looking for exact target name matches before falling back to treating dots as part of an assembly name? This will break compatibility with all targets containing dots in the name. Being a major version change this is valid of course. But could still cause some confusion. |
ecd9173
to
5f62528
Compare
The extension-loading-magic is only done when NLog detects the Type-Symbol-Name contains a dot <extensions>
<add assembly="Elmah.Io.NLog"/> <!-- Registers elmah.io as type-symbol-name -->
</extensions>
<targets>
<target name="elmahio" type="elmah.io" apiKey="API_KEY" logId="LOG_ID"/>
</targets> |
Kudos, SonarCloud Quality Gate passed! |
@snakefoot Makes sense 👍 I think we'll go for a name change, not including the dot. Thank you for the heads up. |
@snakefoot I have tested the elmah.io target with NLog 5 (dev branch) and written some more documentation. I just want to provide a few ideas that you can take or leave, but at least I have written down my thoughts somewhere. I totally understand why you want to support fully qualified references of targets, since adding assemblies in extensions is a common source for confused users and non-working config. But I'm not sure I understand the "schema" you have chosen for the fully qualified name. As I understand it, you will need to reference targets on the following format:
Where a real example could be:
This will require a target implementation in an assembly named I think that this may be misleading for some users since this isn't a fully qualified class name. I could see something like this working:
This would reference the file itself. And for target names it could be:
This includes the assembly name containing the target as well as the target name separated with a comma. The purpose of this comment is not to force you to support:
This would be possible of course, but it's no problem for us to add more Anyway, that is just my thoughts. |
I was thinking that NLog-users standing outside the source-code could easily see 2 things:
So I guess that I could change from dottet format to comma-format, and support both:
Then instead of scanning for dot |
Agree. Real fully-qualified names are probably not preferred. I just think that it's a bit hard to see where the assembly/nuget name ends and where the target name starts with the current solution. The last dot, I know, but could be clearer with the comma for users not into the details. Maybe you should get input from at least one other person that doesn't have a target with a dot in the name before making any changes 😄 |
I kind of like having the assembly-name at the end, since the symblic-name is the most important part. So it should be first, since a nuget-package can contain multiple NLog-extensions. |
Yep agree. I think I had forgotten about the way to reference class names when writing the proposal. |
@ThomasArdal Thank you for the feedback, much appreciated. Have now created #4308 |
Updated wiki: https://github.com/NLog/NLog/wiki/Register-your-custom-component about how to use fully qualified name. |
It seems that using It complains that |
But it works on runtime, right? My memory around this is a bit vague but having a fully qualified name there instead of the add assembly extension should be possible in NLog 5. So, maybe the XSD for the |
But yes NLog uses the format just fine, even though the XML Schema validation fails. |
Oh, yeah of course. |
When using |
Yeah ok. I see that IntelliSense no longer works in the sample. I think we have some URLs to update. Like www to non-www and https). |
Resolves #2944 by allowing you to do this:
Making it easier to specify types from NLog-extension-assemblies without also having to update
<extensions>
Update #4308 Now changed it into this: