Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/.net/25.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# Windows服务中随机出现System.ArgumentNullException_C#_.net_Windows Services_Streamwriter_Argumentnullexception - Fatal编程技术网

C# Windows服务中随机出现System.ArgumentNullException

C# Windows服务中随机出现System.ArgumentNullException,c#,.net,windows-services,streamwriter,argumentnullexception,C#,.net,Windows Services,Streamwriter,Argumentnullexception,我的WCF服务已经部署,我一直面临着这个奇怪的问题。 它已设置为发生错误时自动重新启动 我一直在观察我的服务被随机停止。我没有得到任何相同的记录 它给了我以下的例外 Service cannot be started. System.ArgumentNullException: Value cannot be null. Parameter name: path at System.IO.StreamWriter..ctor(String path, Boolean append, Enc

我的WCF服务已经部署,我一直面临着这个奇怪的问题。 它已设置为发生错误时自动重新启动

我一直在观察我的服务被随机停止。我没有得到任何相同的记录

它给了我以下的例外

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)
下面是它所指向的方法的代码

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();
        }
我不明白这里发生了什么。当我尝试重新启动它时,它一直显示无法启动Windows服务,错误1064错误。但我随后重建了windows服务项目,并尝试再次启动它,然后它就开始了


谁能告诉我这里有什么问题吗?或者有可能防止这种情况发生的方法?

我认为很明显,
GetConfigurationValue(“ErrorLog”)
返回null。由于错误在您重建和重新部署后消失,我猜
GetConfigurationValue
需要一些构建工件来返回一个值,并且可能该构建工件正在以某种方式被删除或修改?但考虑到缺乏细节,这完全是瞎猜。我会尝试的一件事是在重新部署之前区分现有部署的目录和构建输出(如果您是从构建目录运行的,我会停止这样做,或者复制目录)。