简体   繁体   中英

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

I have a .net windows service I have developed and I am familiar with how to debug it using Visual Studio and attaching the debugger to the process. I also have the service writing to log files throughout its processing to assist in debugging. The problem I am running into is that when some users install my service and try to start it, it gives some generic error saying it couldn't start. I have extensive logging in the start up processes in the service, but not a single one gets written even though I have one before anything else. Here is relevant service code:

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();

           }

    }

Neither the "Service Starting" or the "OnStart" logs get written and I am sure it isn't a problem with permission for the log directory.

My question is this. Are there other ways to figure out what is causing my service not to start?

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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