[RESOLVED] Creating daily Log file - need nudge in right direction
I am using some helpful code found here: http://codingresolved.com/discussion...y-log-files/p1
I have built a simple form based on his sample and wanted to simply log a button press. I am not seeing a clear variable to actually write to the file created daily.... some help would be appreciated since I am intermediate at best and ask a lot of obvious questions....
Here is my sample form:
Code:
Imports System.IO
Public Class Form1
Public Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Label1.Text = DateTime.Now.ToShortDateString
Try
Dim LogFileName As String
LogFileName = DateTime.Now.Day.ToString() + "-" + DateTime.Now.Month.ToString() + "-" + DateTime.Now.Year.ToString()
LogFileName = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + "\Sessions " + LogFileName + " .txt"
Dim fs As New FileStream(LogFileName, FileMode.OpenOrCreate, FileAccess.Write)
'Dim fs As New FileStream("C:\Sessions + '" + LogFileName + "' + .txt", FileMode.OpenOrCreate, FileAccess.Write)
Dim m_streamWriter As New StreamWriter(fs)
Catch ex As Exception
End Try
Timer1.Start()
End Sub '- See more at: http://codingresolved.com/discussion/722/how-to-create-daily-log-files/p1#sthash.N9wLM9zc.dpuf
Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick
Dim day As Integer = DateDiff(DateInterval.Day, CDate(Label1.Text), CDate(DateTime.Now.ToShortDateString))
Dim a As Integer = day
If day >= 1 Then
Dim LogFileName As String
LogFileName = DateTime.Now.Day.ToString() + "-" + DateTime.Now.Month.ToString() + "-" + DateTime.Now.Year.ToString()
LogFileName = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + "\Sessions " + LogFileName + " .txt"
Dim fs As New FileStream(LogFileName, FileMode.OpenOrCreate, FileAccess.Write)
Dim m_streamWriter As New StreamWriter(fs)
Label1.Text = DateTime.Now.ToShortDateString
End If '- See more at: http://codingresolved.com/discussion/722/how-to-create-daily-log-files/p1#sthash.N9wLM9zc.dpuf
End Sub
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim logtext As String = Date.Now & "Macro Created:" & "--" & " " & "Subject:" & " " & "--" & " " & vbCrLf
My.Computer.FileSystem.WriteAllText(HOW DO I POINT THIS TO THE FILE CREATED DAILY?, logtext, True)
End Sub
End Class
Re: Creating daily Log file - need nudge in right direction
You might want to check out the MSDN How Do I video series. This is the link to the VB videos:
http://msdn.microsoft.com/en-us/vstudio/bb466226.aspx
Scroll down about 3/4 of the way down, and you will see their "Windows Development Video Series" which contains videos for logging.
Re: Creating daily Log file - need nudge in right direction
Quote:
Originally Posted by
nO_OnE
You might want to check out the MSDN How Do I video series. This is the link to the VB videos:
http://msdn.microsoft.com/en-us/vstudio/bb466226.aspx
Scroll down about 3/4 of the way down, and you will see their "Windows Development Video Series" which contains videos for logging.
Simply AMAZING, Thank you....
I had done a series of google searches and it kept pointing to event viewer logging in windows and I just hate the event viewer....terrible.
This will solve my problem 100% I am about 1/2 way through the video and it looks like I will be able to do exactly what we wanted plus more without a bunch of extraneous code added. I came from VB6 and have evolved through VS2008-2013 and am finally impressed with the simple yet useful things added
Good Kharma to you sir! I was annoyed at first thinking you were trolling me to go google something but you pointed me to something I was able to learn! :P
Re: Creating daily Log file - need nudge in right direction
Lol, glad to be of assistance!