How Logger works in Prism 4.0 with MEF

Topics: Prism v4 - Silverlight 4, Prism v4 - WPF 4
Mar 18, 2013 at 3:48 AM
Edited Mar 18, 2013 at 5:50 AM

I had newly started working on silverlight & ofcource Prism. I am learning it.

I want to ask one thing How Logger is working in Prism 4.0 with MEF.

At which location it is creating file for logging? I had observed in stockTradder application & found there we are not providing any file for Logging. But they are using Logger .

So I want to know that at which location Logger filer created? How Logger is working in Mef in prism?

If it is automatically creating file then at which location it is creating file?

Can anybody help me for it?

Is there any alternative way is there? I found in that stock trader application that may be they are giving file name in App.config file.

I want to know that can we provide file name, type format etc from cs file?

Is there any other alternative for it?

THanks & Regards
Vipul Langalia
Mar 18, 2013 at 6:41 PM
Edited Mar 18, 2013 at 6:53 PM
Hi Vipul,

By default, Prism provides two loggers, one for Desktop applications and one for Silverlight , as it can seen in the following method of the Bootstrapper class:
protected virtual ILoggerFacade CreateLogger()
    return new EmptyLogger();
    return new TextLogger();
The TextLogger used for Desktop writes a log message to a TextWriter , which by default is the Output console. In other words, the default logger behavior in a Desktop application is to print the messages to the console.
The EmptyLogger used for Silverlight is an empty logger with no implementation inside. In other words, this logger works as a place holder; hence, in Silverlight , the default logger does nothing at all.

The StockTrader RI provides a custom logger in its Desktop version that logs the messages through the Enterprise Library logger, but the Silverlight version uses the default logger; hence, it logs nothing .

Of course, this behavior can be changed in your application by overriding the CreateLogger method and returning the logger you wish to use instead of the default one.

I hope this helps you,

Damian Cherubini
Mar 19, 2013 at 3:54 AM
Hello Damian Thank you for the detail explainations. It really helps a lot. Apart from that I also find that in App.Config file they are provide some file structure & File name "trace". They also mention which items are going to be dumped in that logger
file. So I think When we are doing Logger.Log(...) then it is dumping all the structure with value to file. I also analyse the code using decompiling assembly & find that they are calling Write Method inside. Once again thank you for this detail informations.
It is really very helpful. Regards Vipul Langalia