Enable Log and Trace information for PnP Core Provisioning when using Console Application

Introduction

Looking into PnP Provisioning I noticed there isn’t configuration to set up proper log and trace information (version v2.4.1605).

If you haven’t chance to look into PnP Core solution, and you want to know how to start, take a look here: Office 365 PnP Provisioning starting point.

Anyway, if you’d like to add some extended information about what is happening internally when we are provisioning some site templates, we can achieve it following these steps:

Configuring Log

In app.config (console application) just add these xml inside configuration element.

Including that enables Event viewer information to be displayed directly in the console:

image

IMPORTANT: you can enable this extended information on Azure WebJobs too. Just copy the xml at the end of app.config.

Usage in our Console App

Now, if we also want to log all the Console App information into a file, we should add this code to our main:

Note: Remember we should then use Trace.WriteLine instead Console,WriteLine in our program.

1
2
Trace.WriteLine("");
Trace.WriteLine("Press enter to exit…");

That will create a .log file including the same text and information we see in the console app screen.

 

Author: José Quinto
Link: https://blog.josequinto.com/2016/08/02/enable-log-and-trace-information-for-pnp-core-provisioning-when-using-console-application/
Copyright Notice: All articles in this blog are licensed under CC BY-SA 4.0 unless stating additionally.