Thursday, October 8, 2015

Log4net.dll to Log Information

Log4net.dll to Log Information

Hi Geeks
My new article states how to use the Log4net's external Log4net.dll to log information that might be beneficial for error tracking and other tracing issues.
There are a few things that you need to consider during the implementation. I've also attached the code segment to understand the code better and in a more convenient way for all geeks, who want to implement log4net in their project or for specific their requirements.
You can download the desired Log4net.dll from this path:,
Whilst I've also attached the required Log4net.dll in Solution.
Log4net is an open source project based on the work of many authors. It allows the developer to control what log statements are output with arbitrary granularity. It is fully configurable at runtime using external configuration files. This is how the solution looks after adding this DLL:
We also need to configure the external configuration file; this file is like the root of any application that keeps the information of appenders, filters, config section and much more.
In order to embed the configuration data in the .config file the section name must be identified to the .NET config file parser using a configSections element. The section must specify the "log4net.Config.Log4NetConfigurationSectionHandler" that parses the config section. This type must be fully assembly qualified because it is being loaded by the .NET config file parser, not by log4net.
The correct assembly name for the log4net assembly must be specified. The following is a simple example configuration file that specifies the correct section handler to use for the log4net section. Kindly refer to this link for more in-depth information about this section.
There are two appenders I've used in this sample application named LogFileAppender and SmtpAppender as described below:
<appender name="LogFileAppender" type="log4net.Appender.RollingFileAppender" >for logging information using Log4net object, e.g. log.Debug, log.InfoFormat along with other methods.
SmtpAppender, as shown in the tag <appender name="EmailAppender"type="log4net.Appender.SmtpAppender"> sends mail to an on-demand person or group.
Kindly have a look at the app.config file at least once that plays an important role here and also keeps secure information like under SmtpAppender to send mail to the destination.
To send an email to the desired address you must explore the log.Warn and log.FatalFormat methods.
I've attached the sample application as an attachment. Enjoy coding.
See you soon with more articles.
Thanks, Sachin Kalia

Wednesday, October 7, 2015

Modify the value of readonly varibale

Modify the value of readonly varibale

Concert crowd

The readonly keyword is a modifier that you can use on fields. When a field declaration includes a readonly modifier, assignments to the fields introduced by the declaration can only occur as part of the declaration or in a constructor in the same class.

This is how we declare a readonly variable:

  1: public readonly int objreadonly = 100;

You can only change the value of a readonly variable at the constructor level of the same class.

An Excerpt about readonly is :

A readonly field can only be set upon field initialization or in a constructor. This gives considerable benefit for ongoing maintenance because you can ensure it was set when the object was created and not modified since. Though there is no performance benefit.

I have used a little practical demonstarion of this.

  1: class Readonly
  3:     {
  4: public readonly int objreadonly = 100;
  5:         Readonly()
  6:         {
  7:         }
  8: public void  ChangeValueofReadonly()
  9:         {
 10:             objreadonly = 200;
 11:         }
 12:     }
 13: class Program
 14:     {
 15: static void Main(string[] args)
 16:         {
 17:         }
 18:     }
If you notice I tried to change the value of readonly object "objreadonly" but I'm not successful at changing its value, it issues the error "A readonly field cannot be assigned to (except in a constructor or a variable initializer)" also depicted below in the snap shot.


In other words you can't change its value at method level at class level. It can change at constructor level only.

Let's do it :


This is a small demonstration that I hope will help you somewhere down the line