Unable to create Logging Profiles for PostSharp Diagnositcs

rschwab's Avatar

rschwab

12 Apr, 2018 03:57 PM

When building a project that uses PostSharp.Patterns.Diagnostics (v5.0.49) using the profile examples from http://doc.postsharp.net/logging-customizing#buildtime, I get an error during the build from postsharp.config:

error PS0176: Unexpected XML element: Logging.

I've tried this as a .pssln in the solution directory, postsharp.config in the project directly, and postsharp.config in a parent directory, all of which refuse to recognize the element. I also tried including the alternate elements from the http://doc.postsharp.net/configuration-schema example but "LoggingProfiles" was not recognized either (though most of the discussions I have seen suggest using the Logging version anyway).

The project being built references the PostSharp.Patterns.Diagnostics package.

Config file-

<?xml version="1.0" encoding="utf-8"?>
<Project xmlns="http://schemas.postsharp.org/1.0/configuration">
  <License Value="(removed)"/>
  <Logging xmlns="clr-namespace:PostSharp.Patterns.Diagnostics;assembly:PostSharp.Patterns.Diagnostics">
    <Profiles>
      <LoggingProfile Name="default" IncludeSourceLineInfo="True">
        <DefaultOptions>
          <LoggingOptions IncludeParameterType="True"/>
        </DefaultOptions>
      </LoggingProfile>
    </Profiles>
  </Logging>
  <!--<LoggingProfiles xmlns="clr-namespace:PostSharp.Patterns.Diagnostics;assembly:PostSharp.Patterns.Diagnostics">
      <LoggingProfile Name="default" />
  </LoggingProfiles>-->
</Project>

Which format is in fact appropriate, and are there additional package references or config namespaces required which are not present in the examples? There does not seem to be any useful runtime access to the profiles aside from building up a profile and its associated defaults from scratch, and as these are described as build-time options I would suspect the profile would do nothing at that point.

  1. 1 Posted by rschwab on 13 Apr, 2018 02:13 PM

    rschwab's Avatar

    As a bit more information, it seems that my trouble with the "new" configuration format may in part be due to a project elsewhere in the solution which was using the 5.0.38 PostSharp package, though it was not involved in what I was trying to build and it was my understanding that the profile format was introduced for version 5. I have tried reproducing this with some of your sample projects to no avail, so I unfortunately do not have a shareable example of the package mix. I at least am able to build one of my projects in isolation, another however still does not recognize the "Logging" element. The project that builds has the PostSharp and Diagnostics packages, the one which does not adds the NLog backend package, all of which are the most recent version (Previously none of them would accept the config).

    All in all it looks like my build error may be less an issue with the configuration and more an issue with unclear errors when building a project in a solution with an incorrect package setup? Though, a clearer indication of which configuration schema applies to the postsharp.config and the .pssln files (and how to set the logging profile options in the .pssln version) would be appreciated.

  2. Support Staff 2 Posted by PostSharp Techn... on 13 Apr, 2018 03:14 PM

    PostSharp Technologies's Avatar

    Hello,

    I have tried to reproduce this behavior, but everything is working for me.

    I have created a new .NET Framework project, added PostSharp.Patterns.Diagnostics 5.0.49 package, copied exactly your configuration as postsharp.config in the project file and added the license key there to the configuration. The I have added one logged method and configured the default logging back-end.

    I there any step missing to reproduce your issue? Are all the PostSharp.* packages which PostSharp.Patterns.Diagnostics package depends on of the same version in your project?

    Eventually, you can send us a project reproducing the issue, so we can find out what exactly is causing it.

    Best regards,
    -tony

  3. Support Staff 3 Posted by PostSharp Techn... on 13 Apr, 2018 03:17 PM

    PostSharp Technologies's Avatar

    Hello again,

    I've sent my reply before seeing your second message. I'll reply again in a minute.

    -tony

  4. Support Staff 4 Posted by PostSharp Techn... on 13 Apr, 2018 03:28 PM

    PostSharp Technologies's Avatar

    So, as I assumed in my first reply, the problem is caused by having different PostSharp* package versions in your solution. Is it possible to have all of the same version? If not, could you please share the structure of your solution, so we can see the dependencies between projects and version of PostSharp* packages referenced in them? Having this, we could identify the exact incompatibility issue happening.

    You can also share a diagnostics build log of your solution. This can be obtained via msbuild YourSolution.sln /v:d > build.log.

    Best regards,
    -tony

  5. 5 Posted by rschwab on 13 Apr, 2018 03:59 PM

    rschwab's Avatar

    Hello,

    This one does seem tricky to duplicate, I've tried to set your example solution up similar to mine but everything works (which is expected, but not useful).

    The general structure of ours is-

    /root
    Postsharp.config
    /common
    /project that works
    /local copy of postsharp.config
    /project that doesn't

    I've updated all the packages to latest through NuGet.

    As per your latest message, I am attaching build logs from clean builds of each project (I actually did the one that fails first). The two postsharp files are the same for these builds, normally the one at the root has the logging configuration commented out. Putting a config in the "doesn't work" project doesn't work either.

  6. Support Staff 6 Posted by PostSharp Techn... on 16 Apr, 2018 10:34 AM

    PostSharp Technologies's Avatar

    Hello,

    since there Log attribute is not used in some projects, the PostSharp plugin is not loaded properly and thus the XML element is not recognizes. Please use the following to make the element conditional:

    <?xml version="1.0" encoding="utf-8"?>
    <Project xmlns="http://schemas.postsharp.org/1.0/configuration">
        <Property Name="LoggingEnabled" Value="{has-plugin('PostSharp.Patterns.Diagnostics')}" Deferred="true" />
        <Logging xmlns="clr-namespace:PostSharp.Patterns.Diagnostics;assembly:PostSharp.Patterns.Diagnostics" Condition="{$LoggingEnabled}">
            <Profiles>
                <LoggingProfile Name="default" IncludeSourceLineInfo="True">
                    <DefaultOptions>
                        <LoggingOptions IncludeParameterType="True"/>
                    </DefaultOptions>
                </LoggingProfile>
            </Profiles>
        </Logging>
    </Project>
    

    We are also considering doing changes to the compiler so that the error is not produced in your case, but for now the above workaround should help you.

    (internal issue #16009)

    Kind regards,
    Daniel

  7. 7 Posted by rschwab on 16 Apr, 2018 03:47 PM

    rschwab's Avatar

    That worked, thank you very much.

    -Ryan

  8. Support Staff 8 Posted by PostSharp Techn... on 25 Apr, 2018 12:27 PM

    PostSharp Technologies's Avatar

    Hello,

    the issue #16009 has been fixed in the current release of PostSharp 5.0.50.
    Should you need further help with this issue, don't hesitate to re-open this discussion.

    Best regards,
    Alex

  9. PostSharp Technologies closed this discussion on 25 Apr, 2018 12:27 PM.

Comments are currently closed for this discussion. You can start a new one.

Keyboard shortcuts

Generic

? Show this help
ESC Blurs the current field

Comment Form

r Focus the comment reply box
^ + ↩ Submit the comment

You can use Command ⌘ instead of Control ^ on Mac