C# Windows服务无法启动-错误1053

C# Windows服务无法启动-错误1053,c#,windows-services,C#,Windows Services,我在网上搜索了很多,但没有找到适合我的解决方案 我用C#开发了一个Windows服务。当我在桌面上安装它时,它就可以正常工作了。我可以停止,启动或重新启动它,它做所有它应该做的。我当前的桌面使用的是Windows101909 当我在Windows Server 2016版本1607上安装此版本时,我在服务应启动时遇到了错误: 我不知道在OnStart函数中需要更改什么 public partial class Webshopfiletransfer : ServiceBase { pr

我在网上搜索了很多,但没有找到适合我的解决方案

我用C#开发了一个Windows服务。当我在桌面上安装它时,它就可以正常工作了。我可以停止,启动或重新启动它,它做所有它应该做的。我当前的桌面使用的是Windows101909

当我在Windows Server 2016版本1607上安装此版本时,我在服务应启动时遇到了错误:

我不知道在OnStart函数中需要更改什么

public partial class Webshopfiletransfer : ServiceBase
{
    private static System.Timers.Timer aTimer;
    private static string logfile = Directory.GetCurrentDirectory() + @"\Webshopfiletransferslog-" + DateTime.Today.ToString("yyyy-MM-dd") + ".txt";

    public Webshopfiletransfer()
    {
        InitializeComponent();
    }

    protected override void OnStart(string[] args)
    {

        writetolog("Service started");
        try
        {
            SetTimer();
            aTimer.Start();
        }
        catch (Exception e)
        {
            writetolog("Error: " + e.Message);
        }
    }

    protected override void OnStop()
    {
        try
        {
            aTimer.Stop();
            aTimer.Dispose();
        }
        catch (Exception e)
        {
            writetolog("Error: " + e.Message);
        }
    }

    private static void SetTimer()
    {
        // Create a timer with a two second interval.
        aTimer = new System.Timers.Timer(30000);
        // Hook up the Elapsed event for the timer. 
        aTimer.Elapsed += OnTimedEvent;
        aTimer.AutoReset = true;
        aTimer.Enabled = true;
    }

    private static void OnTimedEvent(Object source, ElapsedEventArgs e)
    {

        transferfiles("download");
        transferfiles("upload");

        if (!File.Exists(logfile))
        {
            string createText = "Logfile created" + Environment.NewLine;
            File.WriteAllText(logfile, createText);
        }
    }

    private static void transferfiles(string modus)
    {
        //This function works when the service is started
    }

    private static void writetolog(string messagetext)
    {
        string appendText = DateTime.Now.ToLongTimeString() + ": " + messagetext + Environment.NewLine;
        try
        {
            File.AppendAllText(logfile, appendText);
        } 
        catch (Exception e)
        {
            Console.WriteLine("Error: " + e.Message);
        }

    }
}

感谢您提供的好提示。

您对文件系统的访问权限有限的服务器。您是否以管理员身份运行该服务?是否可以将文件的读/写操作更改为具有更多访问权限的网络文件夹?是否在日志中写入任何错误?在安装文件服务器时是否会发生这种情况?对每个文件夹都有访问权限