mirror of
https://github.com/DaKerboul/perun.git
synced 2026-08-09 17:05:39 +02:00
New feature - added simple logging to file
This commit is contained in:
35
02_Windows_App/Perun_v1/01_Classes/LogController.cs
Normal file
35
02_Windows_App/Perun_v1/01_Classes/LogController.cs
Normal file
@@ -0,0 +1,35 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
class LogController
|
||||
{
|
||||
// TBD - via https://stackoverflow.com/questions/20185015/how-to-write-log-file-in-c
|
||||
public static void WriteLog(string strLog)
|
||||
{
|
||||
StreamWriter log;
|
||||
FileStream fileStream = null;
|
||||
DirectoryInfo logDirInfo = null;
|
||||
FileInfo logFileInfo;
|
||||
|
||||
string logFilePath = Path.Combine(Environment.ExpandEnvironmentVariables("%userprofile%"), "Documents") + "\\Perun\\";
|
||||
logFilePath = logFilePath + "Perun_Log_" + System.DateTime.Today.ToString("yyyyddMM") + "." + "txt";
|
||||
logFileInfo = new FileInfo(logFilePath);
|
||||
logDirInfo = new DirectoryInfo(logFileInfo.DirectoryName);
|
||||
if (!logDirInfo.Exists) logDirInfo.Create();
|
||||
if (!logFileInfo.Exists)
|
||||
{
|
||||
fileStream = logFileInfo.Create();
|
||||
}
|
||||
else
|
||||
{
|
||||
fileStream = new FileStream(logFilePath, FileMode.Append);
|
||||
}
|
||||
log = new StreamWriter(fileStream);
|
||||
log.WriteLine(strLog);
|
||||
log.Close();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user