We have a helper assembly that assists developers with logging information. The specific method used for logging has two signatures:
LogToULS(string message)
LogToULS(string message, Microsoft.Sharepoint.Administration.SPDiagnosticsCategory category)
In my application I have created a static class that contains an instance of the SPDiagnosticsCategory that I would like to be used any time the application logs something. If the first signature is used, a generic category is assigned and it is harder to find logged information specific to this application.
My question is if it’s possible to force people to use the second signature any time LogToULS is called from this application or does this need to be accomplished through programmer education?
If you can’t remove the method from the codebase, you could mark it as deprecated, so other programmers get a compiler warning whenever they call it (and IntelliSense will warn against its usage):
As per the
ObsoleteAttributedocumentation, you can passtrueas a second parameter to its constructor to cause a compiler error (not just a warning), but this may break existing code.