Reputation: 17426
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.
Upvotes: 10
Views: 5383
Reputation: 38087
If you control the ILogger
interface, you can leverage the Localizable
attribute with a value of false to indicate the value is not localizable.
For example:
void Info([Localizable(false)] string message);
Upvotes: 15
Reputation: 15244
I ran into this issue and found that the easiest solution was to rename my logging method's parameter from "message" to something else.
CA1303 will only trigger if the relevant parameter or property name contains "Text", "Message" or "Caption". If the parameter is passed to Console.Write
or Console.WriteLine
, the parameter also cannot be named "value" or "format".
Upvotes: 3
Reputation: 617
If you apply the GeneratedCode attribute to a class, Code Analysis will not analyze your class.
Upvotes: 2
Reputation: 21002
Neither FxCop/VS Code Analysis nor the CA1303 rule are configurable to ignore particular targets in this way. You basically have three options:
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.
Upvotes: 3