Error tracking a windows service

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • OpticTygre

    Error tracking a windows service

    What is the best way that anyone has found to capture errors inside a
    windows service? It's pointless to use compilation constants, as you can't
    "debug" a service very easily, and you can't pass in a command line
    arguement (can you?) to tell it to do something special like capture errors
    to a file while it's running. Has anyone figured out any good ways to do
    this type of run-time error capturing?

    Basically, if I were building a standard windows app, I'd just program it so
    when certain command line arguements are passed in, the compiled code would
    know to output information to a file. This saves me time from having to be
    on-site and step through the code line by line. Can you do something like
    that with a windows service?


  • Ray Cassick \(Home\)

    #2
    Re: Error tracking a windows service

    Take a look at using TraceListeners and the application configuration file.


    "OpticTygre " <optictygre@ade lphia.net> wrote in message
    news:DcydnXpBZO PH2BTfRVn-og@adelphia.com ...[color=blue]
    > What is the best way that anyone has found to capture errors inside a
    > windows service? It's pointless to use compilation constants, as you
    > can't "debug" a service very easily, and you can't pass in a command line
    > arguement (can you?) to tell it to do something special like capture
    > errors to a file while it's running. Has anyone figured out any good ways
    > to do this type of run-time error capturing?
    >
    > Basically, if I were building a standard windows app, I'd just program it
    > so when certain command line arguements are passed in, the compiled code
    > would know to output information to a file. This saves me time from
    > having to be on-site and step through the code line by line. Can you do
    > something like that with a windows service?
    >[/color]


    Comment

    • NetworkElf

      #3
      Re: Error tracking a windows service


      "Ray Cassick (Home)" <rcassickNOSPAM @enterprocity.c om> wrote in message
      news:OOVoc0pWFH A.2700@TK2MSFTN GP12.phx.gbl...[color=blue]
      > Take a look at using TraceListeners and the application configuration[/color]
      file.[color=blue]
      >
      >
      > "OpticTygre " <optictygre@ade lphia.net> wrote in message
      > news:DcydnXpBZO PH2BTfRVn-og@adelphia.com ...[color=green]
      > > What is the best way that anyone has found to capture errors inside a
      > > windows service? It's pointless to use compilation constants, as you
      > > can't "debug" a service very easily, and you can't pass in a command[/color][/color]
      line[color=blue][color=green]
      > > arguement (can you?) to tell it to do something special like capture
      > > errors to a file while it's running. Has anyone figured out any good[/color][/color]
      ways[color=blue][color=green]
      > > to do this type of run-time error capturing?
      > >
      > > Basically, if I were building a standard windows app, I'd just program[/color][/color]
      it[color=blue][color=green]
      > > so when certain command line arguements are passed in, the compiled code
      > > would know to output information to a file. This saves me time from
      > > having to be on-site and step through the code line by line. Can you do
      > > something like that with a windows service?[/color][/color]

      I just started with .net, but I've been using the application event log for
      a service I've been working on. Is there a reason not to?


      Comment

      • Jay B. Harlow [MVP - Outlook]

        #4
        Re: Error tracking a windows service

        OpticTygre,
        I currently am using a Try/Catch around my main timer routine, within the
        Catch block I log any exceptions (errors) to the Event Log
        (ServiceBase.Ev entLog).

        As Ray suggests you could also use TraceListeners.

        I am considering "upgrading" my logging to either Log4Net or the Microsoft
        Enterprise Library Logging Block:






        You can pass parameters to a service, the following example demonstrates
        how.

        Find official documentation, practical know-how, and expert guidance for builders working and troubleshooting in Microsoft products.


        Specifically Walkthrough item #7 & Figure 5, the args array to the
        ServiceBase.OnS tart method is the "parameters " to the service. You set these
        parameters in the properties of the Service in Computer Management under the
        Windows Control Panel.

        Alternatively I simply put the settings in the app.config for the service.
        Depending on the needs of the service, I would consider passing the name of
        the "environmen t" to as a Parameter, then used this "environmen t" parameter
        as an indexer into a custom Configuration Section in my app.config... By
        "environmen t" I mean: unit test, system test, QA, Production...

        Hope this helps
        Jay


        "OpticTygre " <optictygre@ade lphia.net> wrote in message
        news:DcydnXpBZO PH2BTfRVn-og@adelphia.com ...
        | What is the best way that anyone has found to capture errors inside a
        | windows service? It's pointless to use compilation constants, as you
        can't
        | "debug" a service very easily, and you can't pass in a command line
        | arguement (can you?) to tell it to do something special like capture
        errors
        | to a file while it's running. Has anyone figured out any good ways to do
        | this type of run-time error capturing?
        |
        | Basically, if I were building a standard windows app, I'd just program it
        so
        | when certain command line arguements are passed in, the compiled code
        would
        | know to output information to a file. This saves me time from having to
        be
        | on-site and step through the code line by line. Can you do something like
        | that with a windows service?
        |
        |


        Comment

        • Ray Cassick \(Home\)

          #5
          Re: Error tracking a windows service

          The event log is fine for things that you can easily document (stopping,
          starting, exceptions during critical areas, etc...) but for debug style
          traces nothing beats a good old fashioned, well formatted text file.

          I have seen sooo many service type apps that try to use the vent log for
          debug type tracing. Makes it a real pain in the butt to actual trace code
          that way, and besides, you can really fill up someone's log file if you're
          not careful.

          "NetworkElf " <sum1@somedomai n.com> wrote in message
          news:eOJVLNuWFH A.3760@TK2MSFTN GP15.phx.gbl...[color=blue]
          >
          > "Ray Cassick (Home)" <rcassickNOSPAM @enterprocity.c om> wrote in message
          > news:OOVoc0pWFH A.2700@TK2MSFTN GP12.phx.gbl...[color=green]
          >> Take a look at using TraceListeners and the application configuration[/color]
          > file.[color=green]
          >>
          >>
          >> "OpticTygre " <optictygre@ade lphia.net> wrote in message
          >> news:DcydnXpBZO PH2BTfRVn-og@adelphia.com ...[color=darkred]
          >> > What is the best way that anyone has found to capture errors inside a
          >> > windows service? It's pointless to use compilation constants, as you
          >> > can't "debug" a service very easily, and you can't pass in a command[/color][/color]
          > line[color=green][color=darkred]
          >> > arguement (can you?) to tell it to do something special like capture
          >> > errors to a file while it's running. Has anyone figured out any good[/color][/color]
          > ways[color=green][color=darkred]
          >> > to do this type of run-time error capturing?
          >> >
          >> > Basically, if I were building a standard windows app, I'd just program[/color][/color]
          > it[color=green][color=darkred]
          >> > so when certain command line arguements are passed in, the compiled
          >> > code
          >> > would know to output information to a file. This saves me time from
          >> > having to be on-site and step through the code line by line. Can you
          >> > do
          >> > something like that with a windows service?[/color][/color]
          >
          > I just started with .net, but I've been using the application event log
          > for
          > a service I've been working on. Is there a reason not to?
          >
          >[/color]


          Comment

          • NetworkElf

            #6
            Re: Error tracking a windows service


            "Ray Cassick (Home)" <rcassickNOSPAM @enterprocity.c om> wrote in message
            news:uUWlajzWFH A.3320@TK2MSFTN GP12.phx.gbl...[color=blue]
            > I have seen sooo many service type apps that try to use the vent log for
            > debug type tracing. Makes it a real pain in the butt to actual trace code
            > that way, and besides, you can really fill up someone's log file if you're
            > not careful.[/color]

            Programming is my second hat (that's why I'm not very good at it). My first
            hat is being an engineer. As you probably know, we know everything. I would
            never fill up an event log... :p Thanks for the info.


            Comment

            Working...