Skip to content
Antony Male edited this page Aug 7, 2014 · 10 revisions

Introduction

Sometimes it's useful to see what Stylet's doing under the hood, particularly if it's not doing something you expect it to, or doing something unexpected.

Thankfully, Stylet can be easily configured to produce logging output, so you can get an insight into what it's doing.

Quick Start

To quickly enable logging, put the following in your Bootstrapper's Configure method:

protected override void Configure()
{
   base.Configure();

   Stylet.Logging.LogManager.IsEnabled = true;
}

This will print log messages to the Output window in Visual Studio. Internally, the default logger uses Trace.WriteLine.

Customising the Logging

You can of course provide your own logger to Stylet, which Stylet will use to print log messages.

First, define a class which implements the Stylet.Logging.ILogger interface:

public class MyLogger : Stylet.Logging.ILogger
{
   public MyLogger(string loggerName)
   {
      // TODO
   }

   void Info(string format, params object[] args)
   {
      // TODO
   }

   void Warn(string format, params object[] args)
   {
      // TODO
   }

   void Error(Exception exception, string message = null)
   {
      // TODO
   }
}

Then, configure the LogManager to use it. As before, in your Bootstrapper's Configure method:

protectedoverride void Configure()
{
   base.Configure();

   Stylet.Logging.LogManager.LoggerFactory = name => new MyLogger(name);
   Stylet.Logging.LogManager.IsEnabled = true;
}
Clone this wiki locally