I have been facing this weird issue with my WCF service which is already Deployed. It has been set to automatic restart in case of errors.
I have been observing my service is getting stopped randomly. And I don't get any log of the same.
It has been giving me below Exception
Service cannot be started. System.ArgumentNullException: Value cannot be null.
Parameter name: path
at System.IO.StreamWriter..ctor(String path, Boolean append, Encoding encoding, Int32 bufferSize, Boolean checkHost)
at System.IO.StreamWriter..ctor(String path, Boolean append)
at CommonNameSpace.Generator.Utility.ExceptionLog(Exception ex) in C:\Users\downstreamdev01\source\repos\Project\MyService\Myservice.Solution\Myservice.BusinessLogic\Utility.cs:line 22
at MyServiceNamespace.MyService.OnStart(String[] args)
at System.ServiceProcess.ServiceBase.ServiceQueuedMainCallback(Object state)
Here is the code of method it is pointing to.
public static void ExceptionLog(Exception ex)
{
string gh = GetConfigurationValue("ErrorLog");
StreamWriter swFileLog = new StreamWriter(GetConfigurationValue("ErrorLog"), append: true);
StringBuilder sbErrorLog = new StringBuilder();
sbErrorLog.AppendLine("******* ERROR Log - START **********");
sbErrorLog.AppendLine("[Date Time]: " + DateTime.Now.ToString());
sbErrorLog.AppendLine("[ex.Source]: " + Convert.ToString(ex.Source));
sbErrorLog.AppendLine("[ex.Message]: " + Convert.ToString(ex.Message));
sbErrorLog.AppendLine("[ex.InnerException]: " + Convert.ToString(ex.InnerException));
sbErrorLog.AppendLine("########### StackTrace - START ###########");
sbErrorLog.AppendLine(" ");
sbErrorLog.AppendLine("[ex.StackTrace]: " + Convert.ToString(ex.StackTrace));
sbErrorLog.AppendLine("[ex.Target Site]: " + Convert.ToString(ex.TargetSite));
sbErrorLog.AppendLine("########### StackTrace - END ###########");
sbErrorLog.AppendLine(" ");
sbErrorLog.AppendLine("******* ERROR Log - END **********");
swFileLog.WriteLine(sbErrorLog.ToString());
swFileLog.Close();
}
I can not understand what is happening here. When I try to restart it, It keeps showing the Could not start Windows Service, Error 1064 error. But I then rebuild the windows service project and try to start it again and it gets started.
Can Anyone tell what can be the issue here? or possible way which can prevent such things?