-
Notifications
You must be signed in to change notification settings - Fork 24
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
NLog's schema (NLog.xsd) ignored in Visual Studio? #256
Comments
After testing in Visual Studio and comparing behavior when editing a Maven POM file (written in XML, uses a publicly downloadable XML Schema just like NLog), the POM file's That might be caused by that unescaped double quote. For those interested, note that you must first enable automatic XML schema download in Visual Studio in Tools > Options... > Text Editor > XML > Miscellaneous > Automatically downlaod DTDs and schemas. |
Not sure where the problem is since this is the value in the online XSD-file: <xs:element name="quoteChar" type="xs:string" minOccurs="0" maxOccurs="1" default=""" /> |
TL;DR: To me, the root Detailed reasoning (that's long, sorry...): @snakefoot I discovered several interesting things that explain what you and I observed. I thought the schema was badly written at first but it seems browsers interpret HTML character references when displaying the document's source code... This leaves us with Visual Studio failing to retrieve the schema... and here things become very interesting. Visual Studio fails to retrieve NLog's schema because NLog seem to rely on the fact that the document processor will try to fetch the XML schema using the XML namespace as a URI. Which is apparently NOT guaranteed to work according to https://www.w3.org/TR/xmlschema11-1/#schema-loc :
Since namespace specified in According to W3C, <root xmlns="$namespace"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="$namespace $uri_to_schema">
<!-- document content -->
</root> Where Current NLog example files don't use
<nlog xmlns="http://www.nlog-project.org/schemas/NLog.xsd"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<!-- document content -->
</nlog> Here is how Maven does it in its POM XML files: <project
xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<!-- document content -->
</project> Which finally leads us to my final suggestion to use the following in NLog config files: <nlog xmlns="http://www.nlog-project.org/NLog-config"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.nlog-project.org/NLog-config https://nlog-project.org/schemas/NLog.xsd">
<!-- document content -->
</nlog> I arbitrarily chose the
I would recommend doing what W3C does (a short HTML page explaining what a NLog.config file is and containing a link to the XSD file maybe). |
My bad, Also, I tried playing a little in Visual Studio, changing the URI and attributes ( Annotations are displayed either if (case 1):
<nlog xmlns="http://www.nlog-project.org/schemas/NLog.xsd">
<!-- document content -->
</nlog> OR if (case 2):
<nlog xmlns="http://www.nlog-project.org/schemas/NLog.xsd"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="whatever https://nlog-project.org/schemas/NLog.xsd">
<!-- document content -->
</nlog> With case 2, Also note that |
Strange both FireFox and Egde can load this https https://nlog-project.org/schemas/NLog.xsd When not using https then redirected to https://nlog-project.org/schemas/NLog.xsd?r=redirect Maybe https only works when not including Really appreciate these investigations, as I would like to have the NLog Wiki / Examples to work out of the box. |
No problem, I'm interested in understanding that issue :) I need to read more specifications and articles and to do some testing on my side. My goal is to have the XML schema annotations to show up in Visual Studio and as many editors as possible, while coming up with a sensible and standard-conforming way of doing it. Note that to me, standards matter and I do not intend to cater to each and every Visual Studio quirk :) For example, the fact that it seems to fetch the schema if only I'm also open to contributing by updating the schema if necessary. For example, the following line didn't validate if I remember correctly (while coming directly from https://github.com/NLog/NLog/wiki/Getting-started-with-ASP.NET-Core-6) <logger name="Microsoft.Hosting.Lifetime" minlevel="Info" writeTo="lifetimeConsole, ownFile-web" final="true" /> It's due to the
|
Think it should be fixed so |
Hi again. I'm finally back regarding this issue. It took me a long time since I had to research this in depth, read specs, articles etc. I'll try to keep this as concise as possible (which is a challenge). Some of the things I'm gonna say might not be 100% accurate, but I think they are enough in the context of this conversation. For the sake of understanding, I have to give some info about the basics. Sorry if you already know some of this. First, an XML namespace's purpose is to uniquely define elements and attributes, which are used in some kind of context. E.g. is
IMPORTANT: There is a fundamental difference between an XML namespace's name and the location of that XML namespace's schema! The name is a unique identifier, nothing else. The schema's location is a place where a schema describing that namespace can be found. Unfortunately, they both tend to start with The "Visual Studio-compatible", fastest, simplest and most backward-compatible thing to do, is to add a <?xml version="1.0" encoding="utf-8" ?>
<nlog xmlns="http://www.nlog-project.org/schemas/NLog.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.nlog-project.org/schemas/NLog.xsd http://www.nlog-project.org/schemas/NLog.xsd">
<!-- XML document content -->
</nlog> But this is the super-careful approach. I would personally prefer something cleaner, but it's up to NLog's dev team (if this is used, the <?xml version="1.0" encoding="utf-8" ?>
<nlog xmlns="https://nlog-project.org/xml-namespaces/NLog-config" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="https://nlog-project.org/xml-namespaces/NLog-config https://nlog-project.org/schemas/NLog.xsd">
<!-- XML document content -->
</nlog> Note that most of the time, using the namespace name in a browser allows to retrieve something. The most frequent thing I could see is that using the XML namespace name in a browser leads to a page explaining shortly what the XML namespace represents in a human-readable HTML document (status code 200, a normal page really). Some return 404 which is totally allowed (XML namespace names are neither required nor forbidden to lead anywhere at all). Here are the details about what happens when using the XML namespace name in a browser:
Also, it is required to define prefixes in XML documents ; <?xml version="1.0" encoding="utf-8" ?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" id="NLog" targetNamespace="http://www.nlog-project.org/schemas/NLog.xsd" elementFormDefault="qualified">
<!-- NLog.xsd schema content -->
</xs:schema> About Visual Studio's behavior, I think the spec considers it an XML processor and if so, they can basically do anything they want regarding schema retrieval. The XML schema spec simply defines specific terms and their meaning to provide some standard vocabulary, but does not enforce anything. See notably section C.2:
That being said, I still find Visual Studio's behavior strange. Note however that it can be due to the current root tag attributes used in |
Thank you for this detailed investigation. If the following example provides working intellisense, then I will probably go with that: <?xml version="1.0" encoding="utf-8" ?>
<nlog xmlns="http://www.nlog-project.org/schemas/NLog.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.nlog-project.org/schemas/NLog.xsd http://www.nlog-project.org/schemas/NLog.xsd">
<!-- XML document content -->
</nlog> But I will try and play with this myself in the weekend, if I can find the time. But agree that all wiki-examples should be updated, so intellisense will be working out of the box. Guess there is bonus task for NLog v6 to produce a NLog.xsd schema-package, that includes intellisense for NLog Targets/Layouts that comes from the soon many official extension-nuget-packages. |
You're welcome :) During your tests, don't forget that I don't know how what I've written will translate to concrete development tasks, but I remain available here if you need me. |
Notice I have not forgotten you, and my promise to test myself and make a decision. But my limited spare time is right now spent on re-writing NLog for ver. 6.0. |
Hello.
I was looking for documentation on the
<nlog>
element in NLog config files. The best I've found so far is the XML schema.While examining it, I noticed this line:
I think the
"""
might make some XML Schema parsing tools fail. It should probably be:The text was updated successfully, but these errors were encountered: