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:
http://logging.apache.org/log4net/download.html,
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.
http://logging.apache.org/log4net/release/manual/configuration.html
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