繁体   English   中英

没有Visual Studio的情况下如何调试Windows服务? (在客户的计算机上)

[英]How can I debug a windows service without Visual Studio? (on a client's machine)

我有一个已开发的.net Windows服务,并且熟悉如何使用Visual Studio对其进行调试并将调试器附加到该过程。 我还提供在整个处理过程中写入日志文件的服务,以帮助调试。 我遇到的问题是,当某些用户安装我的服务并尝试启动它时,它给出了一些一般性错误,表明无法启动。 我已经在服务的启动过程中进行了广泛的日志记录,但是即使我先写了一篇,也没有写过任何一篇。 这是相关的服务代码:

static void Main(string[] args) 
    {
            ServiceBase.Run(new OSAEService());
    }

public OSAEService()
    {
        AddToLog("Service Starting");
        if (!EventLog.SourceExists("OSAE"))
            EventLog.CreateEventSource("OSAE", "Application");

        this.ServiceName = "OSAE";
        this.EventLog.Source = "OSAE";
        this.EventLog.Log = "Application";

        // These Flags set whether or not to handle that specific
        //  type of event. Set to true if you need it, false otherwise.
        this.CanHandlePowerEvent = true;
        this.CanHandleSessionChangeEvent = true;
        this.CanPauseAndContinue = true;
        this.CanShutdown = true;
        this.CanStop = true;
    }

protected override void OnStart(string[] args)
    {
        AddToLog("OnStart");
        //All the rest of my start up processes
    }

public void AddToLog(string audit)
    {
           lock (logLocker)
           {
               string filePath = _apiPath + "/Logs/" + _parentProcess + ".log";
               System.IO.FileInfo file = new System.IO.FileInfo(filePath);
               file.Directory.Create();
               StreamWriter sw = File.AppendText(filePath);
               sw.WriteLine(System.DateTime.Now.ToString("MM/dd/yyyy hh:mm:ss.fff tt") + " - " + audit);
               sw.Close();

           }

    }

“服务启动”或“ OnStart”日志均未写入,我确信日志目录的权限不是问题。

我的问题是这个。 还有其他方法可以找出导致我的服务无法启动的原因吗?

请检查Microsoft Visual Studio 2010远程调试以帮助您调试此服务。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM