Set SharePoint Log Category Level using PowerShell

Recently, when I was working with one of our customers, I wanted to ask him to enable Verbose logging for certain SharePoint log categories. Normally, this is easy using the UI (Central Administration >> Monitoring >> Configure Diagnostic Logging), but how to accomplish this using PowerShell?

 

Simply, setting the SharePoint ULS (Trace) log level can be done using the SharePoint cmdlet Set-SPLogLevel, but how to use this for a certain category? - I had a look on the cmdlet article here https://technet.microsoft.com/en-us/library/ff607887.aspx which has the answer, but not as detailed as it could be!

 

After playing around with this cmdlet, I found that you can for instance set the SharePoint ULS log level to Verbose for the below categories by running the following cmdlet:

  • SharePoint Foundation >> Monitoring
  • SharePoint Foundation >> Logging Correlation Data
  • Web Content Management >> Publishing

 

 Set-SPLogLevel -Identity "Sharepoint foundation:Monitoring", "SharePoint Foundation:Logging Correlation Data", "Web Content Management:Publishing" -TraceSeverity Verbose 

N.B., the above command will only set the trace log level, and not the event log level. Moreover, you will need to run the above command using SharePoint management shell from any of your SharePoint servers.

 

Maybe using this command is not that important if you want to change the log level to any log level but VerboseEx. If VerboseEx is required, then this is exactly what you are looking for...

Note: VerboseEx log level is the most detailed logs that you can get from your SharePoint, and the only way to set it is by using PowerShell.

 

However, If you are investigating a SharePoint issue, i would recommend enabling VerboseEx for all the SharePoint log categories using the below cmdlet and via SharePoint management shell.

Set-SPLogLevel -TraceSeverity Verbose

 

Later, if you want to set the SharePoint log level back to default, just use the cmdlet Clear-SPLogLevel

 

Similarly, If you want to get the SharePoint log level for certain categories, you can run the cmdlet Get-SPLogLevel, as shown below:

 Get-SPLogLevel -Identity "Sharepoint foundation:Monitoring", "SharePoint Foundation:Logging Correlation Data", "Web Content Management:Publishing"