-
Notifications
You must be signed in to change notification settings - Fork 14
/
Logging.cs
61 lines (55 loc) · 2.15 KB
/
Logging.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
using Microsoft.Win32;
using System;
using System.IO;
using System.Net;
using System.Text;
using System.Windows.Forms;
namespace Coffeed
{
public static class Logging
{
static string SUBMIT_LOG_URL = "https://xostme.gr/coffeed/logsubmit.php";
public static string LOG_FILE = Path.Combine(Application.StartupPath, "coffeed.log");
static string NL = Environment.NewLine;
public static void InitLog()
{
MessageBoxManager.Retry = "Report Error";
MessageBoxManager.Cancel = "Ignore";
MessageBoxManager.Register();
if (!File.Exists(LOG_FILE))
{
var WE = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Microsoft\Windows NT\CurrentVersion");
File.AppendAllText(LOG_FILE, $"Coffeed - Version {Program.Version}{NL}");
File.AppendAllText(LOG_FILE, $"Windows: {WE.GetValue("ProductName")} / x64: {Environment.Is64BitOperatingSystem} {NL}{NL}");
}
}
public static void LogError(Exception err)
{
File.AppendAllText(LOG_FILE, $"{DateTime.Now.ToLongDateString()} {DateTime.Now.ToLongTimeString()} {NL} {err.Message} {NL} {err.StackTrace} {NL}{NL}");
}
public static void M(string Message, string Title)
{
if (MessageBox.Show(Message, Title, MessageBoxButtons.RetryCancel, MessageBoxIcon.Error) == DialogResult.Retry)
{
// upload
try
{
WebClient c = new WebClient();
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
c.Headers.Add("User-Agent: Other");
c.Encoding = Encoding.UTF8;
using (c)
{
string filePath = Logging.LOG_FILE;
var serverPath = new Uri(SUBMIT_LOG_URL);
c.UploadFile(serverPath, filePath);
}
}
catch (Exception err)
{
MessageBox.Show(err.Message);
}
}
}
}
}