Error Logging?

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

    Error Logging?

    I was wondering if anyone has simple code (or an example) (maybe in VB.Net)
    that shows how to log a message to a file. This is to be a general logger,
    that might log application errors and/or warnings. I've seen some stuff that
    does this with the EventLog, but that seems a bit much for my needs. I'd
    just like to be able to log to a file.
    I'm figuring, to avoid collision in case another app is trying to log at the
    same time, that I'll add some code to sleep a random number of miliseconds
    and try the write again (allowing for up to 10 retries before considering it
    to be unresolvable).

    Unless someone has a better approach. Please help. It's appreciated.

  • Kerry Moorman

    #2
    RE: Error Logging?

    HockeyFan,

    The Visual Studio help topic "EventLog Class" discusses how to easily create
    your own custom eventlog for a particular application and use it to log
    application events like errors or warnings, etc.

    Kerry Moorman


    "HockeyFan" wrote:
    [color=blue]
    > I was wondering if anyone has simple code (or an example) (maybe in VB.Net)
    > that shows how to log a message to a file. This is to be a general logger,
    > that might log application errors and/or warnings. I've seen some stuff that
    > does this with the EventLog, but that seems a bit much for my needs. I'd
    > just like to be able to log to a file.
    > I'm figuring, to avoid collision in case another app is trying to log at the
    > same time, that I'll add some code to sleep a random number of miliseconds
    > and try the write again (allowing for up to 10 retries before considering it
    > to be unresolvable).
    >
    > Unless someone has a better approach. Please help. It's appreciated.
    >[/color]

    Comment

    • HockeyFan

      #3
      RE: Error Logging?

      But don't you have to "register" the application as an event source?


      "Kerry Moorman" wrote:
      [color=blue]
      > HockeyFan,
      >
      > The Visual Studio help topic "EventLog Class" discusses how to easily create
      > your own custom eventlog for a particular application and use it to log
      > application events like errors or warnings, etc.
      >
      > Kerry Moorman
      >
      >
      > "HockeyFan" wrote:
      >[color=green]
      > > I was wondering if anyone has simple code (or an example) (maybe in VB.Net)
      > > that shows how to log a message to a file. This is to be a general logger,
      > > that might log application errors and/or warnings. I've seen some stuff that
      > > does this with the EventLog, but that seems a bit much for my needs. I'd
      > > just like to be able to log to a file.
      > > I'm figuring, to avoid collision in case another app is trying to log at the
      > > same time, that I'll add some code to sleep a random number of miliseconds
      > > and try the write again (allowing for up to 10 retries before considering it
      > > to be unresolvable).
      > >
      > > Unless someone has a better approach. Please help. It's appreciated.
      > >[/color][/color]

      Comment

      • Kerry Moorman

        #4
        RE: Error Logging?

        HockeyFan,

        Yes, but that is just a call to the EventLog's CreateEventSour ce method.

        Eventlogs seem like a really easy way to do application logging, but maybe
        I'm missing the problem.

        Kerry Moorman


        "HockeyFan" wrote:
        [color=blue]
        > But don't you have to "register" the application as an event source?
        >
        >
        > "Kerry Moorman" wrote:
        >[color=green]
        > > HockeyFan,
        > >
        > > The Visual Studio help topic "EventLog Class" discusses how to easily create
        > > your own custom eventlog for a particular application and use it to log
        > > application events like errors or warnings, etc.
        > >
        > > Kerry Moorman
        > >
        > >
        > > "HockeyFan" wrote:
        > >[color=darkred]
        > > > I was wondering if anyone has simple code (or an example) (maybe in VB.Net)
        > > > that shows how to log a message to a file. This is to be a general logger,
        > > > that might log application errors and/or warnings. I've seen some stuff that
        > > > does this with the EventLog, but that seems a bit much for my needs. I'd
        > > > just like to be able to log to a file.
        > > > I'm figuring, to avoid collision in case another app is trying to log at the
        > > > same time, that I'll add some code to sleep a random number of miliseconds
        > > > and try the write again (allowing for up to 10 retries before considering it
        > > > to be unresolvable).
        > > >
        > > > Unless someone has a better approach. Please help. It's appreciated.
        > > >[/color][/color][/color]

        Comment

        • HockeyFan

          #5
          RE: Error Logging?

          Great. I'll use it then. One question I have though, is can there be
          "collisions " if multiple applications are calling WriteEntry.

          "Kerry Moorman" wrote:
          [color=blue]
          > HockeyFan,
          >
          > Yes, but that is just a call to the EventLog's CreateEventSour ce method.
          >
          > Eventlogs seem like a really easy way to do application logging, but maybe
          > I'm missing the problem.
          >
          > Kerry Moorman
          >
          >
          > "HockeyFan" wrote:
          >[color=green]
          > > But don't you have to "register" the application as an event source?
          > >
          > >
          > > "Kerry Moorman" wrote:
          > >[color=darkred]
          > > > HockeyFan,
          > > >
          > > > The Visual Studio help topic "EventLog Class" discusses how to easily create
          > > > your own custom eventlog for a particular application and use it to log
          > > > application events like errors or warnings, etc.
          > > >
          > > > Kerry Moorman
          > > >
          > > >
          > > > "HockeyFan" wrote:
          > > >
          > > > > I was wondering if anyone has simple code (or an example) (maybe in VB.Net)
          > > > > that shows how to log a message to a file. This is to be a general logger,
          > > > > that might log application errors and/or warnings. I've seen some stuff that
          > > > > does this with the EventLog, but that seems a bit much for my needs. I'd
          > > > > just like to be able to log to a file.
          > > > > I'm figuring, to avoid collision in case another app is trying to log at the
          > > > > same time, that I'll add some code to sleep a random number of miliseconds
          > > > > and try the write again (allowing for up to 10 retries before considering it
          > > > > to be unresolvable).
          > > > >
          > > > > Unless someone has a better approach. Please help. It's appreciated.
          > > > >[/color][/color][/color]

          Comment

          Working...