Creating an Error Log

Hello again,

I have never done this but I thought it was a good ideal unless you can tell me differentlly.

How do you create an error log.

I know I will have to create a table for this, but I dont know how to catch the errors and put them in a file for observance at a later time.

If someone can point me in a direction,code, article,etc. it would be appreciated

Davids Learning



Answer this question

Creating an Error Log

  • MunishGupta

    do you mean to put it at the begining of the class

    dont forget i am still learning

    But you should seriously look into what exception handling each method contains.

    what do you mean

    Davids Learning


  • RD410

    If I use a db file what do i need as far as tables\columns.

    when you use Catch ex as Exception

    That would go into every sub in my app, right This way you can catch as to what sub cause the error.

    Could i use my own like saving data to a dataset, that way I can get,time,what form,what procedure,what ip address did the conflict happen on, user name.

    then how does it know where to put the exception if i use your sceniro

    New to VBE as you can tell. Did VB6 for a while.

    Davids Learning


  • Mitch Walker - MSFT

    Enterprise library is a good item to use but can be a little bit more advanced than beginner to get it initially working in the project - but once it is its great. This gives you lots of various ways to configure where and how your logging items.

    Alternatively you can simply write a plain ASCII text file by your application if that is sufficient.

    You dont have to put a try catch in every method. If there is no try catch in a method then when the exception is thrown the method will fail and it will look for an try catch exception handler in the calling method and work its way back up the call stack. Until it gets to the top and it would then throw and unhandled exception error. But you should seriously look into what exception handling each method contains.


  • Jeff F

    do you mean to a db table or a file

    either way it's nothing hard, whenever you want to log something, either append it to a file, or insert a new row on your table.

    The exception handler in a try...catch block is a good place to do this, e.g.

    Catch ex As Exception
    WriteToEventLog("!!!ERR!!!, ex.message=" & ex.Message)

    Other than that, it's up to decide where you want to log something.

    And yes, it's a good idea, esp. for apps which run without much user intervention

    I have a LogError module if you want it, writes to a log/writes errors/3 levels of logging


  • maddman

    If I use a db file what do i need as far as tables\columns. < Very little, a table called Errors, you could get away with one column, e.g ErrorDescription, But you might want ErrorSeverity too

    You don't have to put a try.. catch in every function/sub, just where it might fall over (e.g. fil I/O), but I put a WriteToLog at the start of every main function, & write out important parameters too, and then at teh end of each, usually writing if it worked or not

    For the simplest logging, I'd go for a logfile, and just append text to it

  • ronnycopeh

    If you don't want to re-create the wheel, you may want to take a look at the Enterprise Library (http://msdn.microsoft.com/library/default.asp url=/library/en-us/dnpag2/html/entlib.asp) which has modules for exception handling and logging. Alternatively, Log4net (http://logging.apache.org/log4net/) has received a fair amount of positive feedback. I haven't tried it personally at this point so YMMV.

    Jim Wooley
    http://devauthority.com/blogs/jwooley



  • Creating an Error Log