Logging

Jounce ships with a default logger that simply writes to the attached debugger.

For more sophisticated debugging (for example, displaying events in the application or sending them to the service via a service for logging) you can implement our own logger. Simply implement the interface ILogger and export the interface. Be sure to only do this once - Jounce currently supports only one non-default logger (but you can certainly import other loggers as you like in your own implementation).

[Export(typeof(ILogger))]
public MyLogger : ILogger
{
}

The logger can have a minimum severity set (the typical Verbose, Information, Warning, Error, and Critical are canned). It should accept a log with a message, an Exception, and a string with arguments to perform string formatting. The "source" is typically the type that called the log (i.e. GetType().FullName) and this is how Jounce logs messages, however, you are welcome to use your own convention.

Last edited Mar 27, 2011 at 2:59 PM by jeremylikness, version 4

Comments

mokdes Jan 10, 2013 at 4:06 PM 
Hi Jeremy,
Null Reference Exception is thrown for this call:
EventAggregator.Publish(new ViewNavigationArgs(typeof(MyView)));
because Logger is not set in the Jounce built in EventAggregatorService class after this call
CompositionInitializer.SatisfyImports(this) in the ApplicationService class.
This only happens when I export the routing from the View and not when I use moduleIntializer and I do not provide an implementation for ILogger interface.

The reason is that this call CompositionInitializer.SatisfyImports(this) creates an instance of MainPage view when I expose the ViewModelRoute through the view and the call to this statement in
public void OnImportsSatisfied()
{
EventAggregator.Publish(new ViewNavigationArgs(typeof(MenuView)));
}
generates the Null ref exception because no ILogger implementation is found in my code nor the default one has been created yet.

Can the Logger property return the built in Logger when not set yet ?

Thanks,

graspieper Feb 16, 2011 at 9:15 AM 
Dear Jeremy,

if I put 'MyLogger' in a referenced assembly,
the "Logger" property of EventAggregatorService equals 'null' within the Publish method.
(Note: the Publish method is called because I navigate towards a view (in a dynamically loaded XAP file) )

If I move the same class to my application, everything is fine.
What could I be doing wrong ?


Kind regards,
Steven De Roo - Belgium

jeremylikness Jan 28, 2011 at 12:00 AM 
Indeed, I did! Thanks.

adrianstoica Nov 12, 2010 at 8:17 PM 
Hi Jeremy,

I believe you meant:

public MyLogger : ILogger

Great stuff! Thanks, Adrian