About Me

reno, NV, United States
As of 2011, I have ten years experience in various technologies as C#, WPF, Java, J2EE, C++. For the past three years, I have been extensively working on various .net and java technologies including but not limited to WPF , C# , WCF and composite application guidance (Prism ).

Tuesday, April 14, 2009

Composite application Guidance Prism Logging







Coming from a Java web development world, I always love the ease of use of apache commons logging, I recently implemented logging in our WPF application based on Composite Application guidance (CAL or Prism v2). We use the Microsoft way of logging, Enterprise Library 4.1. Though the performance is sluggish compared to log4net, we wanted to use this for various other reasons.

This blog entry would help you set up you CAL with enterprise logging. I created a class called CustomLogger. CustomLogger encapsulates Logger. You can either resolve ICustumLogger or ILoggerFacade to use this. ICustomLogger provides interface common to Apache commons logging and ILoggerFacade provides interface common to Enterprise Logging.

First looking at registering the ILoggerFacade. The BootStrapper overrides LoggerFacade to return the customLogger.

internal class Bootstrapper : UnityBootstrapper
{
// CustomLogger is a custom logger implementation.
CustomLogger logger= new CustomLogger();


protected override ILoggerFacade LoggerFacade
{
get
{
return logger;
}
}

protected override void ConfigureContainer()
{
Container.RegisterType(new ContainerControlledLifetimeManager());

base.ConfigureContainer();
}

}

We register two things with the container, the ILoggerFacade and the ICustomLogger. Though there is a mere small additional cost,the benefit of this is huge, ILoggerFacade is used by the CAL to log things in trace.log and ICutomLogger is used by app to log things.

An example of logging using this interface is ...




public XXXXXXXXXPresentationModel(IUnityContainer container,
IMagCardInfoView view,
IEventAggregator eventAggregator,
ICustomLogger logger,
IMagCardCommandsView commandsView,
IRegionManager regionManager)
: base(eventAggregator)
{
logger.Debug("New XXXXXX Presentation model requested.");

}


The ICustomLogger interface looks like



public interface ICustomLogger
{

void Info(string message);


void Debug(string message);


void Warn(string message);



void Exception(string message);

}


The CustomLogger looks like

public class CustomLogger: ICustomLogger, ILoggerFacade
{

public void Info(string message)
{
Logger.Write(message, Category.Info.ToString(), (int)Priority.High);
}


public void Debug(string message)
{
Logger.Write(message, Category.Debug.ToString(), (int)Priority.High);
}


public void Warn(string message)
{
Logger.Write(message, Category.Warn.ToString(), (int)Priority.High);
}


public void Exception(string message)
{
Logger.Write(message, Category.Exception.ToString(), (int)Priority.High);
}


#region ILoggerFacade Members

public void Log(string message, Category category, Priority priority)
{
Logger.Write(message, category.ToString(), (int)priority);
}

#endregion
}


1 comment:

Unknown said...

Your life will be a blessed and balanced experience if you first honor your identity and priority. See the link below for more info.


#priority
www.ufgop.org

Followers

Blogger Syntax Highliter