Question about ILog and WinRT blenadbility

Topics: Getting Started
Jan 24, 2013 at 8:44 AM

Hi @all,

I want to use the LogManager in my code as well as I think this is a very good thing.  So I followed the Approach of Caliburn.Micro.Logging. I also Mako use of blendability by adding a designcontext to the XAML.
>     d:DataContext="{d:DesignInstance vm:MainPageViewModel, IsDesignTimeCreatable=True}"
and my ViewModel I have
>         protected readonly ILogExtended Log = LogManager.GetLog(typeof(MainPageViewModel)) as ILogExtended;
and
>             Log.Info("Designmode: "+Execute.InDesignMode.ToString());
this line produces 'Object reference not set to an instance of an object'.
What can I do to overcome this?

Jan 27, 2013 at 4:43 AM

where do you in the initial start of the application tell the LogManager to use a type of ILogExtended?  Bootloader?

Jan 28, 2013 at 8:10 AM

Hi,

It's a WinRT App. First call to LogManager is in configuration method. My workaraound to check Execute.IsDesignMode in front of call to Log.

Jan 28, 2013 at 4:37 PM

only reason I ask is that you appear to be using a custom variant of ILog.  I guess the first thing to check is it the Log or is it the DesignTime support that is throwing the error..

Jan 28, 2013 at 5:51 PM

Hi,

this was the first thing i checked and so i found to this workaround. However, I would like to understand why the exception is thrown and correct my code or file an issue.

Jan 29, 2013 at 8:24 AM

One more Thing: I observed, that when using Navigationservice, the contructor of ViewMode receives the NavigationService as Parameter. If I reference the ViewModel in XAML as designcontext I get an error saying 'Class has no parameterless contructor'. What is the Workaround?

Please Keep in mind I am doing WinRT Apps.

Jan 29, 2013 at 8:26 AM
mvermef wrote:

only reason I ask is that you appear to be using a custom variant of ILog.  I guess the first thing to check is it the Log or is it the DesignTime support that is throwing the error..


Hi mvermef,

I use customized Version of http://buksbaum.us/2010/08/08/how-to-do-logging-with-caliburn-micro/, But this seems not to be the Point. When I remove ILogExtented it's the same behaviour.

Jan 29, 2013 at 4:51 PM

Ok I understand that you probably have some more stuff going on with your logger but how are you setting it up initially in the Configure override?

LogManager.GetLog = type => new YourLogger(type);

?

Jan 29, 2013 at 4:54 PM
Edited Jan 29, 2013 at 5:06 PM

that tells the LogManager to use this implementation of YourLogger, since the logger is asking for a Type in the constructor that is what we are giving it.

Other wise LogManager doesn't have any implementation other than NullLogger as per the default in source of Logging.cs

Now... when you want to get a variable to play with you use ILog _log = LogManager.GetLog(typeof(YourViewModel));

_log.Info("Blah Blah");

Jan 31, 2013 at 8:22 AM
Thats exactly how I did it. First call to LogManager is in configuration, subsequent calls implicit in ViewModel Initializer.
Feb 4, 2013 at 8:49 PM
can't help further without some more source to see and how you setup your DesignTime Data.
Feb 5, 2013 at 6:34 AM
OK, I'll send you a link for download.