Is this advisable to use Mutex object to synchronize request/response xmls writing for WCF service? Is there any better approach for it?
Background We have one very old WCF service which uses by some other Java service and thousands of users use that.
To troubleshoot some prod issues I am implementing logging to capture all the request and response xmls so It will have huge logging.
Since multiple process are trying to write on same xml file i am getting IO exception and to resolve that I thought to use Mutex based on below link however my queries are
- Is this advisable to use it for my service? thousands of requests would hit service in a day so my service would become slower due to mutex ?
- what is the best solution for this type of situation. I am sure this is very common scenario where it is required to log lot to troubleshoot issues in WCF.
OR LOCK OR Monitor Object should be ok in my case while wrinting to log file? my service is with ConcurrencyMode Multiple OR Mutix is required ?
Note: Since this is very old service, i don't have an option to use Log4Net library here.
Thanks for your help.
Like below method I have around 30 methods which log request and response xml and for that I am getting IO error - file is in use.
Code
WebMethod1(object Request)
{
string requestId = Guid.newguid().tostring()
LogRequestResponse(Request)
response = CallOtherService();
LogRequestResponse(response);
}
LogRequestResponse(object xmlReqRes)
{
try
{
using(StreamWriter myWriter = new StreamWriter(filePath, true, Encoding.UTF8))
{
xmlSerializer mySerializer = new xmlSerializer(xmlReqRes.GetType())
mySerializer.Serialize(myWriter, xmlReqres);
}
}
catch {}
}