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

Microsoft TechDays 2013

Last week I presented at the Microsoft TechDays 2013 in The Hague, Netherlands. I want to thank the attendees for joining my session on Developing SharePoint 2013 Apps with Visual Studio 2012. The last session before the weekend after 2 days filled with sessions, big shout out to them!

You can find my slides and demo source code on Bram de Jager on TechDays on www.macaw.nl

Other colleague speakers are Arie Leeuwesteijn with Async and parallel patterns and application design (level 200 in Dutch) and Dion Olsthoorn with Bouw cross-platform mobiele apps met PhoneGap (level 200 in Dutch).

Word text generator for Lorem Ipsum

Regularly I need Word documents with example text. Word has a example text generator feature which creates text like “Lorem ipsum dolor sit amet, consectetuer …” or “On the Insert tab, the galleries include items that are designed …” or “The quick brown fox jumps over the lazy dog. The quick brown fox …”.

Simply start Word and type =lorem(3,10) and press Enter

Word 2010, lorem ipsum function

This results in:

Word 2010, lorem ipsum result

There are some options you can use:

  • =lorem(p, l) where p is the number of paragraphs and l the number of lines per paragraph.
  • =rand(p,l) provides the same functionality but using different text “On the Insert tab, the galleries include items that are designed …
  • =rand.old(p,l) also provides the same functionality using different text “The quick brown fox jumps over the lazy dog. The quick brown fox …

Maybe you already knew, maybe not. I was looking for the “The quick brown fox jumps over the lazy dog. The quick brown fox …” text and thought lets share!

How to recover a crashed VM

Last week it happened again, one of my virtual machines crashed. And I needed a way to repair the virtual machine or at least retrieve the files located on the virtual hard disk.

Important note: This is (probably) not supported and I can’t guarantee your virtual machine is recovered. Please only use this how-to as your last resort! It might help you 🙂

What happened?: When the virtual machine (VM) crashed it needed a forced shutdown. When restarting the VM it came back with Recovery mode. I wasn’t able to start Windows normally!

Solution: Within VirtualBox (I’m currently using Oracle VM VirtualBox), or any other virtualization software, you are able to mount multiple hard disks. You need to mount the hard disk of the crashed VM to another healthy VM (which works normally). Pay attention to snapshots, mount the latest snapshot! Start the healthy VM.

What happens?: The healthy VM will pick up the crashed hard disk and starts scanning and repairing the hard disk. After repairing Windows will start normally and you are able to browse the hard disk and retrieve your files.

If you are having a lucky day? You could try to shutdown the healthy VM. Unmount the hard disk (which was repaired). And try starting your crashed VM. Now you know whether you are really lucky! It might start!? Good luck!