开发者

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

开发者 https://www.devze.com 2023-04-06 17:02 出处:网络
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 through

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 sa开发者_开发技巧ying 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?


Please check the Microsoft Visual Studio 2010 Remote Debugger to help you debug this service.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号