Skip to content
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

Expected Serilog001 on extension method doesn't report warning when building with MSBuild #54

Open
thorhj opened this issue Feb 3, 2021 · 0 comments

Comments

@thorhj
Copy link

thorhj commented Feb 3, 2021

I have created extension methods over Serilog's ILogger. When I call these method incorrectly, embedding an exception in the message template instead of passing it as the first parameter, I expect the Serilog001 warning to appear.

using System;
using Serilog;
using Serilog.Core;

namespace BuggyAnalyzerTest
{
    class Program
    {
        static void Main(string[] args)
        {
            // Expecting Serilog001 here:
            Log.Logger.MyError("The following exception was thrown: {Exception}", new Exception());
        }
    }

    static class LoggerExtensions
    {
        [MessageTemplateFormatMethod("messageTemplate")]
        public static void MyError(this ILogger logger, Exception ex, string messageTemplate, params object?[] propertyValues)
        {
#pragma warning disable Serilog004
            logger.Error(ex, messageTemplate, propertyValues);
#pragma warning restore
        }

        [MessageTemplateFormatMethod("messageTemplate")]
        public static void MyError(this ILogger logger, string messageTemplate, params object?[] propertyValues)
        {
#pragma warning disable Serilog004
            logger.Error(messageTemplate, propertyValues);
#pragma warning restore
        }
    }
}

When I build this code using dotnet build (using dotnet 3.1.100 SDK), the warning appears as expected.
However, when I build using MSBuild (for instance through Visual Studio 16.8.4), the build is unexpectedly successful.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant