Enable ULS logging during App deployment

Troubleshooting is always afterwards, meaning you need logging information to backtrack the origin of the errors. But normally the logging level is set to default and the actual interesting data is missing from the ULS logs.

This post provides an approach to enable logging before deploying your apps and reverting to the default afterwards.

Before making changes to the ULS diagnostic settings you want to backup/export your settings. Doing this from the Central Administration is not your preferred way or you must love to copy and past a lot.

LoggingInCentralAdmin

Export the diagnostic logging levels

You can easy export your settings by using PowerShell. Below a script which exports the diagnostic settings for the ULS logging levels. This script will export the logging levels to a CSV-file.

Get-SPLogLevel | Export-Csv "$($env:USERPROFILE)\Downloads\$((Get-Date).ToString("yyMMddHHmmss"))_LogLevels.csv" -NoTypeInformation

After opening the export in Excel, you get the data shown below.

ExportLoggingLevelsInExcel

Use PowerShell to get and/or update logging level

To get and/or update a particular log level via PowerShell you need to know how to scope the identity of the logging level. Once you know it, it’s pretty simple! The identifier is a combination of Area and Name.

Get-SPLogLevel -Identity "Search:General"

Change logging levels for App deployment

The general steps you want to include in your deployment scripts is based on lowering the logging for a predefined set of logging levels. Next execute the deployment and afterwards revert to the default.

  • Lower logging levels to Verbose
  • Execute deployment
  • Revert to default logging levels

Download the full PowerShell script here.

Lower the logging levels to Verbose

Below you find a script which sets a predefined set of logging levels. This set can be used as a basic for every deployment or configuration change. It is not set in stone that this is all you need, please update it to fit your needs.

Set-SPLogLevel -identity 'Search:Logging Correlation Data' -EventSeverity Verbose -TraceSeverity Verbose Set-SPLogLevel -identity 'SharePoint Foundation:Logging Correlation Data' -EventSeverity Verbose -TraceSeverity Verbose Set-SPLogLevel -identity 'SharePoint Server:Logging Correlation Data' -EventSeverity Verbose -TraceSeverity Verbose Set-SPLogLevel -identity 'SharePoint Foundation:Configuration' -EventSeverity Verbose -TraceSeverity Verbose Set-SPLogLevel -identity 'SharePoint Foundation:Database' -EventSeverity Verbose -TraceSeverity Verbose Set-SPLogLevel -identity 'SharePoint Foundation:Feature Infrastructure' -EventSeverity Verbose -TraceSeverity Verbose Set-SPLogLevel -identity 'SharePoint Foundation:General' -EventSeverity Verbose -TraceSeverity Verbose Set-SPLogLevel -identity 'SharePoint Foundation:Timer' -EventSeverity Verbose -TraceSeverity Verbose Set-SPLogLevel -identity 'SharePoint Foundation:Topology' -EventSeverity Verbose -TraceSeverity Verbose Set-SPLogLevel -identity 'SharePoint Foundation:Upgrade' -EventSeverity Verbose -TraceSeverity Verbose Set-SPLogLevel -identity 'SharePoint Foundation:PowerShell' -EventSeverity Verbose -TraceSeverity Verbose Set-SPLogLevel -identity 'SharePoint Foundation:App Deployment' -EventSeverity Verbose -TraceSeverity Verbose Set-SPLogLevel -identity 'SharePoint Foundation:App Management' -EventSeverity Verbose -TraceSeverity Verbose Set-SPLogLevel -identity 'SharePoint Foundation:App Marketplace' -EventSeverity Verbose -TraceSeverity Verbose Set-SPLogLevel -identity 'SharePoint Foundation:Application Authentication' -EventSeverity Verbose -TraceSeverity Verbose Set-SPLogLevel -identity 'SharePoint Foundation:Authentication Authorization' -EventSeverity Verbose -TraceSeverity Verbose Set-SPLogLevel -identity 'SharePoint Foundation:CSOM' -EventSeverity Verbose -TraceSeverity Verbose Set-SPLogLevel -identity 'SharePoint Foundation:CSOM Api' -EventSeverity Verbose -TraceSeverity Verbose Set-SPLogLevel -identity 'SharePoint Foundation:App Hosting Quota Management' -EventSeverity Verbose -TraceSeverity Verbose Set-SPLogLevel -identity 'SharePoint Foundation:App Monitoring' -EventSeverity Verbose -TraceSeverity Verbose Set-SPLogLevel -identity 'SharePoint Foundation:App Auth' -EventSeverity Verbose -TraceSeverity Verbose Set-SPLogLevel -identity 'SharePoint Portal Server:Runtime' -EventSeverity Verbose -TraceSeverity Verbose Set-SPLogLevel -identity 'SharePoint Portal Server:Long Running Operation' -EventSeverity Verbose -TraceSeverity Verbose Set-SPLogLevel -identity 'SharePoint Server:General' -EventSeverity Verbose -TraceSeverity Verbose Set-SPLogLevel -identity 'SharePoint Server:Setup and Upgrade' -EventSeverity Verbose -TraceSeverity Verbose Set-SPLogLevel -identity 'SharePoint Server:Database' -EventSeverity Verbose -TraceSeverity Verbose

Revert back to the default logging levels

Revert the logging levels to the default, after executing the deployment or configuration changes.

Clear-SPLogLevel

Advertisements
Leave a comment

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: