-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathLog.cs
76 lines (67 loc) · 2.09 KB
/
Log.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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
using System;
using System.IO;
using System.Reflection;
namespace ISO_8583_MessageSandbox
{
public static class Log
{
private static string LogFilePath
{
get
{
var currentLocation = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
return currentLocation != null
? $"{LogFilePath}\\ISO_8583_MessageSandbox_log.txt"
: "c:\\ISO_8583_MessageSandbox_log.txt";
}
}
static Log()
{
if (!File.Exists(LogFilePath))
{
File.Create(LogFilePath);
}
}
public static void Write(string message)
{
using (var streamWriter = File.AppendText(LogFilePath))
{
streamWriter.Write(message);
}
}
public static void WriteLine(string message)
{
using (var streamWriter = File.AppendText(LogFilePath))
{
streamWriter.WriteLine(message);
}
}
public static void WriteBytes(byte[] message)
{
using (var streamWriter = File.AppendText(LogFilePath))
{
for (var i = 0; i < message.Length; i++)
{
streamWriter.WriteLine("message[{0}] = {1}", i, message[i]);
}
}
}
public static void WriteHex(byte[] message)
{
var hex = BitConverter.ToString(message).Replace("-", string.Empty);
using (var streamWriter = File.AppendText(LogFilePath))
{
streamWriter.WriteLine(hex);
}
}
private static string ByteArrayToHex(byte[] byteArray)
{
var hex = BitConverter.ToString(byteArray);
return hex; //.Replace("-", "");
//StringBuilder hex = new StringBuilder(byteArray.Length * 2);
//foreach (byte b in byteArray)
// hex.AppendFormat("{0:x2}", b);
//return hex.ToString();
}
}
}