Writing to Logs

Write to the C1 CMS's log from your code

You can use C1 CMS's logging functionality to write to the log from your code. This functionality is based on Microsoft Enterprise Library (the EntLib Logging Application Block) which you can configure to use the Event Log and other providers and write custom providers for if needed.

Examples of code that writes data to the log:

using System;
using Composite.Core;

public class LoggingExample
{
    public static void DoABC()
    {
        Log.LogInformation("ABC", "Starting to do ABC");

        bool SomethingGoesWrong = true;
        try
        {
            if (SomethingGoesWrong == true)
            {
                Log.LogWarning("ABC", "Something is wrong with " + "...");
            }
        }
        catch (Exception e)
        {
            Log.LogError("ABC", "Failed to do ... ");
            Log.LogError("ABC", e);
        }
    }
}

Please also see C1 CMS API logging examples.

You can also consult the EntLib Logging Application Block documentation on how to customize logging. The configuration settings are located in ~/App_Data/Composite/Composite.config.

Stack Trace

A stack trace provides information on the execution history of the current thread when the exception occurred and displays the names of the classes and methods called at that very moment.

Normally, it is logged as an Error entry with a few extra lines to fit all the information. In the example above, a call to Log.LogError("ABC", e); will display a stack trace if the exception occurs.