TraceSeverity.None Throws Exception

TraceSeverity flags are leveraged to report varying levels of criticality to the ULS log. By properly leveraging the TraceSeverity flag, a developer can provide critical information to the SharePoint Administrator to assist in diagnosing code or service-related issues.

As you can see, the TraceSeverity enumeration includes the flag of “None”. If a developer attempts to use TraceSeverity.None, it will throw an exception, similar to this:

Unhandled Exception: System.ArgumentException: Specified value is not supported for the severity parameter. at Microsoft.SharePoint.Administration.SPDiagnosticsServiceBase.WriteTrace(UInt32 id, SPDiagnosticsCategory category, TraceSeverity severity, String output, Object[] data) at ConsoleApplication3.Program.Main(String[] args)

This appears to be by design. In the SPDiagnosticServicesBase.WriteTrace method, we can see that Microsoft intended to throw this exception when using TraceSeverity.None:

public void WriteTrace(uint id, SPDiagnosticsCategory category, TraceSeverity severity, string output, params object[] data)
{
    if (category == null)
    {
        throw new ArgumentNullException("category");
    }
    if (!Enum.IsDefined(typeof(TraceSeverity), (int) severity) || (severity == TraceSeverity.None))
    {
        throw new ArgumentException(string.Format(CultureInfo.InvariantCulture, SPResource.GetString("InvalidArgumentText", new object[0]), new object[] { "severity" }));
    }

In addition, using EventSeverity.None will throw a similar error.

Trevor Seward is a Microsoft Office Apps and Services MVP who specializes in SharePoint Server administration, hybrid scenarios, and SharePoint Online. He has been working with SharePoint for 16 years from SharePoint 2003 on up, managing environments with terabytes of content for 150,000+ user organizations. Trevor is an author of Deploying SharePoint 2016 and Deploying SharePoint 2019. You can find him on Twitter and in /r/sharepoint.