Try Catch und in Log Schreiben

  • VB.NET

Es gibt 2 Antworten in diesem Thema. Der letzte Beitrag () ist von Razer.

    Try Catch und in Log Schreiben

    Hallo,

    Ich will in dem Sub alles per Try und Catch anweißung sichern.

    und zwar so, dass wenn ex as Exception gecacht wird, dass dieser Fehler sofort in eine error.log eingeschrieben wird...
    Wie mach ich das? (bitte mit Try anweißung)

    also:

    try
    code
    catch ex as ex...
    in applicationordner & "\logs\error.log" schreiben
    end try

    Danke
    Razer
    Wo dein Pseudocode steht musst du einfach einen filewriter nehmen.
    Beispiel:

    VB.NET-Quellcode

    1. Try
    2. '...
    3. Catch ex As Exception
    4. Using fw As New System.IO.StreamWriter(IO.Path.Combine(Application.ExecutablePath, "err.log"))
    5. fw.WriteLine(Err.Description)
    6. End Using
    7. End Try
    Oder (Ich habs inzwischen schon selber auch geschafft, davor^^)

    VB.NET-Quellcode

    1. Imports System.IO


    VB.NET-Quellcode

    1. Try
    2. ...
    3. Catch ex as Exception
    4. Dim sw As StreamWriter = New Streamwriter(Application.StartupPath & "\logs\errors.log")
    5. sw.WriteLine(ex)
    6. sw.Close()
    7. End Try