locked
log4net usage RRS feed

  • Question

  • User8275 posted

    Hi,

    We are trying Xamarin for a mobile development under iOS and Android. We have a lot of code in C# that we want to reuse and this code contains a lot of log4net statements.

    Has anybody successfully compiled log4net under Xamarin? Other approach?

    Ideally we want to use the same C# code - used in some other .NET application under Windows. Keeping log statements as is ...

    Thanks, Didier

    Wednesday, April 10, 2013 3:49 PM

All replies

  • User119 posted

    Hi

    Our team has worked on log4net in the course of proting SharpSNMP to MT/MA, but skipped it (delayed) just because log4net is very "unfriendly" for mobile apps (read not so easy to port), because:

    1. it comes from web/server side bringing in dependencies not suitable for mobile platforms
    2. depends heavily on xml configuration files (and You probably know todays hype is to throw that out - see service stack et al)
    3. uses archaic ArrayLists and Hashtables - this needs to be addressed with newer collections

    Out team has managed to split log4net on desktop version (netfx client profile) and netfx (asp.net included).

    Now we have options (haven't made decisions yet):

    • either to add missing links to mobile platforms (Mail notifications, etc)
    • throw offending/problematic stuff out

    TODOs:

    1. unit tests (regression checks)
    2. MA + MT (MA has currently 20+ errors and when done MT should not be very difficult)
    3. WP (new collections)

    If You need more info and help just ask me

    Tuesday, April 16, 2013 8:44 AM
  • User8164 posted

    I got into this today hoping to get it to work as we're working on sharing a bunch of code between our server and mobile code bases. It turns out it's practically done for you.

    Here's some steps I think should get it building for you: 1) grab the source 2) open the log4net 2010 solution (it opens fine in 2012) 3) make a Xamarin.Android or Xamarin.Touch project (or a PCL) and duplicate the folder structure you see in the solution and for each folder add the same files the solution has but as links (you could just dump them all into the project too but I like to duplicate the structure for maintainability) 4) Compile it and watch it fail
    5) Every place you get an error should be within a #if with a line very similar to "#if !NETCF && !SSCLI && !CLIENT_PROFILE". It turns out the parts of the .NET framework that are missing in Xamarin that log4net wants were also missing in the .NET Compact Framework (NETCF).

    You can use __ANDROID__ for Xamarin.Android and add your own for Xamarin.iOS, or if you're using a pcl just add one, and include the flag appropriately in those #if statements and you'll compile.

    I didn't try to get the test assembly to build but I imagine it's a similar scenario. I would argue against spending time on it since you're just linking in the log4net raw files and you could just run the test assembly against those in the solution rather than bothering with it per platform.

    Tuesday, April 23, 2013 11:49 PM