This project is created as a Class Library using Visual Studio 2008. It uses the external libraries
  • log4Net logging framework. More information @ http://logging.apache.org/log4net/
  • nunits - unit testing framework. More information @ http://www.nunit.org

Log4Net
The log4Net library is used for logging. The logging related code is present in the logging namespace.
The log4Net can be downloaded from http://logging.apache.org/log4net/download.html.
The log4Net library requires a configuration file for generating logs. If no config file is present the logging is ignored.

The sample config file I use is:

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<configSections>
<section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler,log4net" />
</configSections>

<log4net debug="true">

<root>
<level value="DEBUG" />
<appender-ref ref="NormalMessageLogFileAppender" />
<appender-ref ref="ErrorFileAppender" />
</root>

<appender name="test" type="log4net.Appender.RollingFileAppender">
<file value="Logs/Messages" />
<appendToFile value="true" />
<rollingStyle value="Size" />
<maxSizeRollBackups value="10" />
<maximumFileSize value="10MB" />
<staticLogFileName value="true" />
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%date [%thread] %-5level %logger [%property{NDC}] - %message%newline" />
</layout>
</appender>

<appender name="NormalMessageLogFileAppender" type="log4net.Appender.FileAppender">
<file value="Logs\Messages.txt" />
<appendToFile value="true" />
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%date [%thread] %-5level %logger [%property{NDC}] - %message%newline" />
</layout>
</appender>

<appender name="ErrorFileAppender" type="log4net.Appender.RollingFileAppender">
<file value="Logs\Errors" />
<param name="AppendToFile" value="true" />
<filter type="log4net.Filter.LevelRangeFilter">
<levelMin value="ERROR" />
<levelMax value="FATAL" />
</filter>
<rollingStyle value="Composite"/>
<maxSizeRollBackups value="10" />
<maximumFileSize value="10MB" />
<staticLogFileName value="false" />
<datePattern value="-yyyy-MM-dd. \x\m\l " />
<layout type="CommonLibrary.GBXmlLayout">
<locationInfo value="true" />
</layout>
</appender>
</log4net>
</configuration>

I add this to NETChannels.dll.config file. Place this in my bin folder or from where the dll is loaded. This will create the Messages file with logs in it at the log level of DEBUG. This level can be changed. Ensure that the directory specified is present.

The Assembly.cs file contains the reference to the configuration file which needs to be changed to the file name. (I have merged in the file with the properties to be added.)

NUnits
The code is tested using the nunits framework. It can be downloaded from http://www.nunit.org/?p=download
The test directory has the tests written for testing. Add the NUnit.exe as the external executable to run when debugging. This will start with all tests. The tests for socketchannel are present under SocketChannelTest class.

Last edited Jan 20, 2011 at 8:44 AM by rsankarx, version 1

Comments

No comments yet.