Archive

Archive for the ‘WCF’ Category

How to use Log4Net with WCF in DOT NET

May 14, 2016 2 comments

This post will help you to configure LOG4NET with WCF Application , Log4Net is basically a logging engine which have many advanced feature to help you completely in your logging need of your application

So lets break the implementation in step basis.

Step 1.

Download the log4Net from any authorized source like :(https://www.nuget.org/packages/log4net/) or (https://logging.apache.org/log4net/download_log4net.cgi)

after downloading reference your LOG4Net in your project as below

1

Step 2.

Configure your Configuration File (Web.config) as below


 <configSections>
<section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler"/>
</configSections>
<log4net>
<!-- RollingFile is set to be a File Appender -->
<appender name="RollingFile" type="log4net.Appender.RollingFileAppender">
<file value="log4netLogging.log" />
<appendToFile value="true" />
<maximumFileSize value="1MB" />
<maxSizeRollBackups value="2" />
<datePattern value="yyyyMMdd" />
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%date [%thread] %-5level %-50logger %-20method - %message%newline%newline" />
</layout>
</appender>
<!-- Set root logger level to DEBUG and its only appender to RollingFile -->
<root>
<level value="DEBUG" />
<appender-ref ref="RollingFile" />
</root>

</log4net>
</configuration>

Step 3.
Make a class that will act as base class for your other class wherever you would like to use the logging.


public class ServiceBase
{
private readonly ILog log;
public ServiceBase()
{
//Load log4net Configuration
XmlConfigurator.Configure();
//Get logger
log = LogManager.GetLogger(typeof(ServiceBase));
//Start logging
log.Debug(&amp;amp;quot;ServiceBase Constructor calling&amp;amp;quot;);

}
}

Step 4.

Now Implement above created base class to your service and use the log.


public class Service1 : ServiceBase, IService1
{
private readonly ILog log;
public Service1() : base()
{
//Get logger for Service1
log = LogManager.GetLogger(typeof(Service1));
}

public string GetData(int value)
{
log.Info(&amp;amp;quot;Entering GetValue()&amp;amp;quot;);

return string.Format(&amp;amp;quot;You entered: {0}&amp;amp;quot;, value);
}

}

Now you can run and go to your project , log file will be created there

If you face any issue then you can reach out me at ::https://www.facebook.com/kumar20sujeet

You can  download Source code from my GITHUB Repository from :Here

Advertisements
Categories: WCF Tags:

Web Services vs WCF services

April 5, 2012 5 comments

Many times I saw asking differences between web services and WCF services so this made me write this.

There are numbers of differences between both , so lets understand step by step.

–WCF offers much more flexibility and portability to develop a service when comparing to web service. Still we are having more advantages over Web service.
more more details you can visit at http://msdn.microsoft.com/en-us/magazine/cc163674.aspx[^]

Features Web Service WCF
Hosting It can be hosted in IIS It can be hosted in IIS, windows activation service, Self-hosting, Windows service
Programming [WebService] attribute has to be added to the class [ServiceContract] attribute has to be added to the class
Model [WebMethod] attribute represents the method exposed to client [OperationContract] attribute represents the method exposed to client
Operation One-way, Request- Response are the different operations supported in web service One-Way, Request-Response, Duplex are different type of operations supported in WCF
XML System.Xml.serialization name space is used for serialization System.Runtime.Serialization namespace is used for serialization
Encoding XML 1.0, MTOM(Message Transmission Optimization Mechanism), DIME, Custom XML 1.0, MTOM, Binary, Custom
Transports Can be accessed through HTTP, TCP, Custom Can be accessed through HTTP, TCP, Named pipes, MSMQ,P2P, Custom
Protocols Security Security, Reliable messaging, Transactions

hope this will help you to understand.

If this help you in understanding the concept then like and share it to your friends.

Categories: WCF Tags:
%d bloggers like this: