-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLogWriter.cs
More file actions
63 lines (54 loc) · 1.75 KB
/
LogWriter.cs
File metadata and controls
63 lines (54 loc) · 1.75 KB
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
using System;
using System.Collections.Generic;
namespace FileRipper
{
public class LogWriter
{
// Private Constructor
private LogWriter()
{
_logQueue = new List<Log>();
}
#region Private Properties
private static LogWriter _instance; // Instance of Logwriter
private static List<Log> _logQueue; // Queue
#endregion Private Properties
// Public "Constructor"
public static LogWriter Instance()
{
return _instance ?? (_instance = new LogWriter());
}
// Method for Logging
public void LogFileRip(string status, string message, string server)
{
var vals = new Log {Status = status, Message = message, Server = server};
//LogFileRip(vals);
AddToQueue(vals);
}
// Adds to private queue
private void AddToQueue(Log log)
{
_logQueue.Add(log);
Flush(false);
}
// Actually Logs to SQL Server
private static void SendLog(Log log)
{
const string qs = @"INSERT INTO [JJFDEVELOPMENT].[SCM].[dbo].[FileRipLog] ([Status],[Message],[Server]) VALUES (@Status, @Message, @Server)";
SqlMapperUtil.InsertUpdateOrDeleteSql(qs, log);
}
// Flush Queue
public void Flush(Boolean isEnd)
{
// Thousand Count limit
if (_logQueue.Count < 1000 && !isEnd) return;
foreach (var log in _logQueue)
{
// Merges
SendLog(log);
}
// Clears List
_logQueue.Clear();
}
}
}