Je voudrais créer un fichier log pour suivre les évènements d'erreur survenues dans l'application 8)
Version imprimable
Je voudrais créer un fichier log pour suivre les évènements d'erreur survenues dans l'application 8)
Salut !
J'ai fais ca pour un projet,
+++Code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26 'USAGE : ' On Error GoTo Err_handler ' Exit Sub 'Err_handler: ' If Err.Number <> 0 Then ' errLogger Err.Number, Err.Description, "Function_source_of_error", "File", True ' Err.Clear ' Resume Next ' End If Public Sub errLogger(ByVal lNum As Long, ByVal sDesc As String, ByVal sFrom As String, ByVal sFile As String, Optional ByVal printMsgBox As Boolean = False) Dim fp As Integer fp = FreeFile Open App.path & "\Trace\Errors " & Day(Now()) & "-" & Month(Now()) & "-" & Year(Now()) & ".log" For Append As #fp Print #fp, "-----------------------------------------------------------------------------------------" Print #fp, Now() & " -> Error generated by the function : " & sFrom & " in file : " & sFile & ". Description : " & lNum & " - " & sDesc Print #fp, "-----------------------------------------------------------------------------------------" Close #fp If printMsgBox = True Then MsgBox "An unknown error has occured : '" & sDesc & "'," & vbCrLf & "Please refer to Errors " & Day(Now()) & "-" & Month(Now()) & "-" & Year(Now()) & ".log file in 'Trace' folder for details", vbOKOnly + vbCritical, "Error" End If End Sub
Ju