Logging

Logging in Code

To be able to write to the C1 CMS log, you should use the static methods of the Composite.Core.Log class: LogCritical, LogError, LogWarning, LogInformation, LogVerbose.

Sample # 1:

using Composite.Core;

namespace Demo
{
    public class Class5
    {
        public static void PageViewed()
        {
            Log.LogInformation("Demo", "A page has been viewed");
        }
    }
}

Download the source

Sample # 2:

using System;
using System.IO;
using Composite.Core;

namespace Demo
{
  public class Class5
  {
    public static void TestLog()
    {
        try
        {
            using (StreamReader sr = new StreamReader("NonExistingFile.txt"))
            {
                String line;
                while ((line = sr.ReadLine()) != null)
                {
                    Log.LogInformation("Demo", line);
                }
            }
        }
        catch (Exception e)
        {
            Log.LogError("Demo", "The file could not be read");
            Log.LogError("Demo", e.Message);
            Log.LogError("Demo", e);
        }    
    }
  }
}

Download the source

Read more on Composite.Core.Log

Please also see Logging.