This is not really an issue but more of a standard.
using Silly.Services.CarPark.Logging;
using Silly.Services.CarPark.ServiceContracts.Common.v1;
using log4net;
using System.Linq;
using System.Threading.Tasks;
using WcfClientProxyGenerator;
namespace Silly.Services.CarPark.Client
{
public class RequestManager
{
private static Log4NetLoggingAdapter systemLogger;
private static IRequestService proxy = null;
public RequestManager()
{
if (systemLogger == null)
{
LoggerSetup.Configure(Constants.ModuleNameForLogging);
systemLogger = new Log4NetLoggingAdapter(LogManager.GetLogger(typeof(RequestManager)));
}
proxy = WcfClientProxy.Create<IRequestService>(c =>
{
c.SetEndpoint("BasicHttpBinding_IRequestService");
c.OnCallBegin += (sender, args) => { };
c.OnBeforeInvoke += (sender, args) =>
{
systemLogger.Write(string.Format("{0}.{1} called with parameters: {2}", args.ServiceType.Name, args.InvokeInfo.MethodName, string.Join(", ", args.InvokeInfo.Parameters)), Core.EventSeverity.Verbose);
};
c.OnAfterInvoke += (sender, args) =>
{
systemLogger.Write(string.Format("{0}.{1} returned value: {2}", args.ServiceType.Name, args.InvokeInfo.MethodName, args.InvokeInfo.ReturnValue), Core.EventSeverity.Verbose);
};
c.OnCallSuccess += (sender, args) =>
{
systemLogger.Write(string.Format("{0}.{1} completed successfully", args.ServiceType.Name, args.InvokeInfo.MethodName));
};
c.OnException += (sender, args) =>
{
systemLogger.Write(string.Format("Exception during service call to {0}.{1}: {2}", args.ServiceType.Name, args.InvokeInfo.MethodName, args.Exception.Message), args.Exception, Core.EventSeverity.Error);
};
});
}
}
}
If I have seven more services, I'll be writing six more proxies and i see redundant code. Can I use generics here? Aim is to keep redundant code to the minimum. I have removed the actual logging I'm doing and since I created the proxies, I have been changing the string and I have to do it at four different locations (four services so far)