-
Notifications
You must be signed in to change notification settings - Fork 0
/
LogWriter.cs
48 lines (43 loc) · 1.45 KB
/
LogWriter.cs
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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
/*
* Created by SharpDevelop.
* Date: 31.08.2017
* Time: 20:32
*
*/
using System;
using System.IO;
using System.Reflection;
namespace LDAP2CSV
{
/// <summary>
/// Description of LogWriter.
/// </summary>
public static class LogWriter
{
private static StreamWriter textStream;
private static readonly string _logFileName = "err.log";
/// <summary>
///
/// </summary>
/// <param name="entry"></param>
public static void CreateLogEntry(string entry)
{
string _logFilePath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), Assembly.GetExecutingAssembly().GetName().Name, "log");
if (!Directory.Exists(_logFilePath))
Directory.CreateDirectory(_logFilePath);
try
{
if (!File.Exists(Path.Combine(_logFilePath, _logFileName)))
textStream = File.CreateText(Path.Combine(_logFilePath, _logFileName));
else
textStream = File.AppendText(Path.Combine(_logFilePath, _logFileName));
textStream.WriteAsync(string.Format("{0}" + Environment.NewLine, entry.Replace("\r\n", "; ").Insert(0,DateTime.Now.ToString() + " ")));
textStream.Close();
textStream.Dispose();
}
catch
{
}
}
}
}