Managing C# fragment and .NET assembly Template Building Block logs

You can configure the logging performed during publishing so that you can examine the log messages produced by C# fragment Template Building Blocks and .NET assembly Template Building Blocks when you publish an item.

If you are working with a C# fragment Template Building Block and you are not able to debug the fragment, but you can get access to its log messages, you can make your C# fragment write its log messages to a specific log file and/or to a console.

Similarly, you may want to make your .NET assembly Template Building Block write its log messages to a specific log file and/or to a console If you are debugging a .NET assembly Template Building Block while publishing an item. Typically, you debug .NET Template Building Blocks by following the instructions in Debugging Compound Templates. That is, you run a Template from the Template Builder client application and examine the Output window to see what, if anything, goes wrong during Template execution. You then use this information to set breakpoints in your .NET code, and debug the code.

However, some problems with your Template may only occur while you are publishing content. In that case, you can still attach your .NET project to the publish process (as explained in Debugging .NET assembly Template Building Blocks remotely), and set breakpoints in your .NET code, but since you are not using Template Builder, there is no Output view in which to examine the log messages produced by the .NET assembly Template Building Block being executed. You must access the log elsewhere.

Setting the logging level

By default, the C# and .NET Template Building Blocks produce log messages of the following log levels during publishing:

  • Information
  • Warning
  • Error

When debugging, you may want to configure the log level so that it also logs Verbose debug messages.

To set the log level to Verbose, do the following:

  1. On the Content Manager server machine, access the config\ subfolder of %TRIDION_HOME% (defaults to C:\Program Files (x86)\Tridion\).
  2. In this folder, open the file Tridion.ContentManager.config in a plain-text or XML editor. Find the following element: configuration > tridion.templating > debugging.
  3. Add a templatingLogLevel attribute to this element, and set it to the value Debug. For example:

    <debugging pdbDirectory="c:\Temp" templatingLogLevel="Debug" />
  4. Save and close the Tridion.ContentManager.config file.
  5. From the Windows Administrative Tools, access Services and locate the service called Tridion Content Manager Publisher. Restart this service.

Logging to file

By default, the Publisher (including any C# fragment or .NET assembly Template Building Block involved in the publish action) logs to the Windows Event Log. You can configure the Publisher to also log to a file. To do this, do the following:

  1. On the Content Manager server machine, access the bin\ subfolder of %TRIDION_HOME% (defaults to C:\Program Files (x86)\Tridion\).
  2. In this folder, open the file TcmPublisher.exe.config in a plain-text or XML editor. Find the following element: configuration > loggingConfiguration > categorySources. Within this element, find an add element that has its Value attribute set to the value Tridion.ContentManager.Templating.TemplatingLoggingCategory.
  3. Inside the listeners subelement of this element, remove the comment delimiters around the line:

    <!--add name="Tridion CM Publisher Log File" /-->

    so that it reads

    <add name="Tridion CM Publisher Log File" />
  4. The .NET assembly or C# fragment now writes log messages to an output file, which defaults to the file Tridion.ContentManager.Publisher.log in the log\ subfolder of %TRIDION_HOME% (defaults to C:\Program Files (x86)\Tridion\). You can change the path and/or file name by finding the element configuration > loggingConfiguration > listeners and finding the add subelement that has its name attribute set to the value Tridion CM Publisher Log File. Change the value of fileName attribute of this same element to set an alternative output path and/or filename.Note: If you have activated logging of publisher actions using the SDL Tridion MMC Snap-in (as explained in a separate configuration topic), the Publisher itself also logs its messages to this log file.
  5. Save and close the TcmPublisher.exe.config file.
  6. From the Windows Administrative Tools, access Services and locate the service called Tridion Content Manager Publisher. Restart this service.

Logging to console

By default, the Publisher (including any C# fragment or .NET assembly Template Building Block involved in the publish action) logs to the Windows Event Log. You can configure the Publisher to also log messages to the console from which you run the Publisher. To do this, do the following:

  1. On the Content Manager server machine, access the bin\ subfolder of %TRIDION_HOME% (defaults to C:\Program Files (x86)\Tridion\)
  2. In this folder, open the file TcmPublisher.exe.config in a plain-text or XML editor. Find the following element: configuration > loggingConfiguration > categorySources. Within this element, find an add element that has its Value attribute set to the value Tridion.ContentManager.Templating.TemplatingLoggingCategory.
  3. Inside the listeners subelement of this element, remove the comment delimiters around the line:

    <!--add name="Tridion Console Trace Listener" /-->

    so that it reads

    <add name="Tridion Console Trace Listener"/>
  4. Save and close the TcmPublisher.exe.config file.
  5. The C# fragment or .NET assembly now writes log messages to a command prompt console in which the Publisher runs.Note: the Publisher itself also logs its messages to this console.Your next step is to run the Publisher in debug mode in a command prompt console.
  6. From the Windows Administrative Tools, access Services, and locate the service called Tridion Content Manager Publisher. Stop this service.
  7. Start a Windows Command Prompt and navigate to the bin\ subfolder of %TRIDION_HOME% (defaults to C:\Program Files (x86)\Tridion\).
  8. Enter the following command to start the Publisher in debug mode:

    TcmPublisher.exe -debug
  9. Whenever you publish an item, the console now displays all messages produced by C# fragment Template Building Blocks and/or .NET Template Building Blocks that are executed as part of publishing the item.