Skip to content

Logging

Gurmit Teotia edited this page Jan 3, 2020 · 4 revisions

Guflow has in built basic mechanism to generate the logs and it does not rely on third party library to generate the logs. However you can use any third party library to generate the log out of Guflow.

To enable the logging in Guflow you need to register the logger in the beginning of your program as shown in following example:

private static async Task MainAsync(string []args)
{
   //It will cause the Guflow log messages to be send to console.
   Log.Register(Log.ConsoleLogger);
   ...
}

Built-in loggers: Guflow supports following built-in loggers:

  • Log.ConsoleLogger: It will send the log message to console.
  • Log.NullLogger: No log messages are generated.

Custom logger: To use the custom/third party logger for Gulow you need to derive a class from Guflow.ILog as shown in following example:

class CustomLog : ILog
{
   private readonly string _typeName;
   private ILogger _custom; //It can be third party logger.
   public ConsoleLog(string typeName)
   {
      //some third party logger e.g. Log4Net
      _custom = LogManger.GetLogger(typeName);
      _typeName = typeName;
   }
   public void Info(string message)
   {
      _custom.Info(message);
   }
   public void Info(string message, Exception exception)
   {
       _custom.Info(message, exception);
   }
   public void Debug(string message)
   {
       _custom.Debug(message, exception);
   }
   .....
}

and register it with Guflow to be used:

Log.Register(type=>new CustomLog(type.Name));
Clone this wiki locally