Search code examples
.netcode-analysissuppression

Can I suppress all code analysis messages for a certain class?


Whenever I call my logger in a method, e.g.

_logger.Debug("Connecting to database...");

I get the warning:

CA1303 : Microsoft.Globalization: 
Method 'Database.Connect()' passes a literal 
string as parameter  'message' of a call to 'ILogger.Debug(string)'. 
Retrieve the following string(s) from a resource table instead: 
"Connecting to database...".

Is there a way to suppress this warning every time I use a function of ILogger? I really don't want to suppress it in every method I'm using it.


Solution

  • Neither FxCop/VS Code Analysis nor the CA1303 rule are configurable to ignore particular targets in this way. You basically have three options:

    1. Suppress the violations individually,
    2. Disable the rule, or
    3. Substitute a custom rule that behaves the way you would prefer.

    I tend to lean toward #3 for this sort of thing, but ymmv... Also, if you feel strongly that you ought to be able to control the CA1303 behaviour, this is something to consider requesting at https://connect.microsoft.com/VisualStudio or http://visualstudio.uservoice.com/forums/121579-visual-studio.