How to configure an interface usiong UNity to log either in file or database

  • Thread starter Thread starter wakefun
  • Start date Start date
W

wakefun

Guest
Dear all,

I have WCF service class which is in charge of provinding different contract method through different enpoints.
Those services are accessible using SOAP or REST.

The idea is that at ther service side, I need to log information for each method call and catch exception.
Those information might be store in database or a single file which is based on the client choice to use the service.

What I was thinking off is to provide a dependency injection to be used by each service method in order o handle the log operation automatically.

For exemple I have the following interface for a sample service and datacontract :

public interface IDataService
{
//
[OperationContract]
[WebInvoke(Method="GET",
RequestFormat =WebMessageFormat.Json,
ResponseFormat =WebMessageFormat.Json,
BodyStyle = WebMessageBodyStyle.Wrapped,
UriTemplate ="json/GetData")]
//This method sample return POC data in Json format
DataResponse GetDataJson();
}

And my datacontract

public class DataResponseBase
{
[DataMember]
public Status Status { get; set; }
[DataMember]
public string Message { get; set; }
[DataMember]
public string StackInfo { get; set; }

}



Serviuce implementation goes as below :

public partial class TestService : IDataService
{
private ServiceMethods _svcMethods;


public TestService()
{

........
}


}

Now if I need to implement and Interface Ilogger, which is should log either on databse or file depending on the implementation, at which level should I inject it ?

  1. At service implementation constructor?
  2. At each service method parameter ?

What the Ilogger and its implentation will look like to swithc between databse log or file log ?

Thnaks for guide lines or sample

regards

Continue reading...
 
Back
Top