Question

I am writing windows mobile (6.5.3) application on MC9190 device (CF 3.5). I want to log certain events (e.g. user login info) and any runtime exceptions occurred. How can I do that? I tried to use log4net from this example http://breathingtech.com/2009/using-apache-log4net-in-net-compact-framework-projects/ But CF 3.5 is not supported. (http://logging.apache.org/log4net/release/framework-support.html). How can I log events/exceptions in my application? Is there any standard log framework available for CF 3.5? Thank you.

Was it helpful?

Solution

Writing a simple logging is not that hard. Regardless which logging you implement, you need to add a line for each exception or event you want to log. Log4Net and other frameworks are full blown and support techniques that are not usable on Compact Framework (ie log to system event log). So you must decide on your own, if it is worth to use a framework where you cannot use most of the features supported in the full framwork.

There are also some more simple logging tools: http://blogs.msdn.com/b/davidklinems/archive/2006/08/17/704662.aspx

See also: Logging Library for .NET Compact Framework?

The problem with log4net and it's compact framework support is that is mostly not maintained over the time (as with other open source libs too).

Getting a working log4net for compact framework is easy:

  • Open the log4.net src/log4net.vs2008.sln
  • Add a new SmartDevice class library project (WM5 SDK and CF2 is OK) and name it log4netCF
  • delete the existing class1.cs file
  • change the project properties: enter image description here Assembly name and Default namespace = "log4net"

  • Now just right click every source code folder in the log4net.vs2008 project in solution explorer and select copy and then right click log4netCF project and select paste Repeat that for every single folder:

    • Appender,
    • Config,
    • Core,
    • DateFormatter,
    • Filter,
    • Layout,
    • ObjectRenderer,
    • Plugin,
    • Repository,
    • Util
  • also copy the single files:

    • AssemblyInfo.cs
    • AssemblyVersionInfo.cs
    • GlobalContext.cs
    • ILog.cs
    • LogicalThreadContext.cs
    • LogManager.cs
    • MDC.cs
    • NDC.cs
    • ThreadContext.cs

    from log4net.vs2008 into the log4netCF project.

  • delete Properties/AssemblyInfo.cs in log4netCF project
  • add PocketPC;NETCF_2_0;NETCF to the build options of log4netCF enter image description here

Now right click the log4netCF project and select Build. It should build without any error and you have a working Compact Framework 2.0 log4net assembly.

A dropin of the project file is available at www.hjgode.de/temp/log4netCF.csproj. Just download and place into your subversion copy of log4net into the src folder beside the log4net.vs2008.csproj file.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top