Contents
What is log4net?
Advantages of log4net.
To do logging using log4net.dll in CF 2.0 we need to do a couple of things.
Use a new Device Application project from Smart device project in Visual Studio 2008.
Convert Log4net.dll into a .Net Compact Framework 2.0 Class Library (*.dll).
Add the new log4netCF.dll to the project using "Add reference".
Now you will see the output in the simulator.
Figure 1 Select Smart Device Project
Figure 2 Select Device Application
Figure 3 Device Application Main Form
Figure 4 Errors using log4Net
Figure 5 Change Project Properties
Figure 6 Change Project Properties
Figure 7 Add Log4netCF.dll
Figure 8 Config.xml File
Figure 9 Change Properties of Config.xml File
Figure 10 Add 3 Buttons to Main Screen
Figure 11 Create Logger
Figure 12 Create Log Button Click Event Code
Figure 13 Open Log Click Event Code
Figure 14 Clear Button Click Event Code
Figure 15 Opt 1 Main Screen
Figure 16 Opt 2 Click On Create Log Button
Figure 18 Opt 4 Click Open Log File to read It
Figure 17 Opt Log.txt is Created Now
What is log4net?
Log4net is an open source library that allows .NET applications to log output to a variety of sources (for example, the console, SMTP or files). Log4net is a port of the popular log4J library used in Java. The full details of log4net can be found at http://logging.apache.org/log4net/index.html
Advantages
The advantages of log4net are:
1. Works with .NET 1.0 & 1.1: The much improved logging of EntLib 2.0 and above is only available if your application is running on .NET 2.0 or greater. log4net however works on all versions of .NET.
2. Simpler install: When using the Enterprise Library there are some services you really should install. This is as simple as running a bat file included with EntLib but it does complicate your deployment process.
3. Slightly faster: log4net was significantly quicker than EntLib 1.1 logging. EntLib 2.0 onwards has improved its performance but log4net remains slightly faster. A benchmark I found while researching my presentation had EntLib taking approximately 5-6 seconds to log 100,000 entries while log4net took about 3 seconds. Does the speed difference matter? Probably not. However log4net net does support.
4. Appender Buffering: Buffering support with some appenders lets log4net queue up log entries and write them in a single batch. If you are writing entries to the database then buffering is a good way to improve performance.
5. More platforms: The Enterprise Library does not support the .NET Compact Framework whereas log4net does.
To do logging using log4net.dll in CF 2.0 we need to do a couple of things; they are:
- We must use the Compact Framework 2.0 installed in our computer or you can download it from: http://www.microsoft.com/en-in/download/details.aspx?id=22808
- We need to download the log4net.dll from the link: http://logging.apache.org/log4net/download.html. We need the Source Code of that log4net.dll.
- We need to convert the log4net.dll into a DLL that can work in the Compact Framework 2.0.
Using the project
Now to use the new Device Application project from the Smart device project in Visual Studio 2008.
To use new Device application project,
go to the "File" menu in Visual Studio 2008 then select "New" => "Project..." then select "Smart Device Project".

Figure 1 Select Smart Device Project
Press "Ok" and now select "Device application Project".

Figure 2 Select Device Application
Press "Ok" and you will see the screen like this:

Figure 3 Device Application Main Form
Conversion
Now to convert the Log4net.dll into the .Net Compact Framework 2.0 Class Library (DLL file).
If you use the log4net.dll then it will give you an error like this after writing the code for the logging data from the application.

Figure 4 Errors using log4Net
Why do we need to covert?
The problem with log4net and its Compact Framework support is that is mostly not maintained over the time. Or Simply We are making the .dll file that can compatible with Compact Framework 2.0.
So we need to convert the log4net.dll to a CF 2.0 Class Library (DLL file) and then you can use that in you project.
So here is the procedure:
















Vipin RanePosted Dec 25, 2014, 6:13 AM
Nice article on logging into text file. Can you please add example/code for logging into database of smart device application.
Konanki VamsiPosted Nov 23, 2014, 2:58 PM
In the emulator I'm able print error text, but its not appending to the txt file !!!,
Colin CraddockPosted Sep 23, 2014, 12:09 PM
Worked for me. Struggled for hours with this one. Much appreciated
LARRYPosted Aug 2, 2014, 9:16 AM
Thank you for this! Struggled many hours trying to find a solution to this issue.