views:

223

answers:

3

I want to add some logging capability to a cf.net application running on WM6 Pro. I'm looking at logging exceptions and some of the more sensitive sections of code. I would like to have logs stored both locally (i.e. on the device) and also have them reliably uploaded to a server as well (they will need to be queued, my app is occasionally connected).

Does anyone know if this possible with log4net or will I have to write my own logging system? Does anyone have any pointers?

A: 

It's possible to do that. Just write custom appender that checks if server is available and stores data in sqlite if not.

http://karlagius.wordpress.com/2008/01/02/writing-a-custom-appender-for-log4net/

Artem Tikhomirov
A: 

SQL CE (Compact Edition) supports replication. You can store the exceptions locally, then synchonize the local datastore with a central server when connected. Some details here.

Dave Swersky
I'd avoid this approach. Writing to a SQL CE database is more likely to fail than writing to a text file, and (although MS doesn't advertise this) SQL CE replication is unreliable when the network connection is dropped during replication (which happens quite a bit with mobile devices).
MusiGenesis
Thanks for your input Dave but I agree with MusiGenesis. It's the SQLCE and SQLCE replication issues that I'm mainly interested in logging :)
Christopher Edwards
+4  A: 

If you use log4net for this, DO NOT use the UDP appender option to log to a remote server. If the WM device is connected to a PC via ActiveSync and accessing the net through the PC, attempting to use UDP will crash ActiveSync in a way that requires a reboot of the PC and a soft reset of the WM device. I had a demo go horribly wrong because of this (we lost a huge contract).

log4net may be great in other environments, but I've found it to be a PITA and not worth the trouble in Windows Mobile. You're better off writing your own simple Logger class that uses a TextWriter to dump info into a text file (for local logging) or calls a webservice function on a remote server. You have total control over what gets written where, and you don't need any Chainsaw nonsense just to read your logs.

MusiGenesis
Ah the joys of mobile development and people hack-porting desktop libs to the CF.
ctacke
Thanks MusiGensis. I was thinking of just spewing each event out to an xml file in a folder with a completely separate exe just waking up the device every so often and sending the files to a webservice (no file notifications in CE). I suppose I could fire off the exe from my code too.
Christopher Edwards