-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLog.cs
55 lines (45 loc) · 1.52 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
using System;
using Google.Api;
using Google.Cloud.Logging.Type;
using Google.Cloud.Logging.V2;
namespace Updater
{
public static class Log
{
private static readonly LoggingServiceV2Client googleCLient = LoggingServiceV2Client.Create();
public static void Debug(String message)
{
log(message, LogSeverity.Debug);
}
public static void Info(String message)
{
log(message, LogSeverity.Info);
}
public static void Error(String message)
{
log(message, LogSeverity.Error);
}
public static void Critical(String message)
{
log(message, LogSeverity.Critical);
}
private static void log(String message, LogSeverity severity)
{
message = $"{DateTime.Now:HH:mm:ss} {severity} - {message}";
Console.WriteLine(message);
if (!Config.isLocal())
{
var logName = new LogName(Config.googleProject, Config.environment + "-updater");
var resource = new MonitoredResource {Type = "project"};
var logEntry = new LogEntry
{
LogName = logName.ToString(),
Severity = severity,
TextPayload = message
};
logEntry.Labels.Add("env", Config.environment);
googleCLient.WriteLogEntries(LogNameOneof.From(logName), resource, null, new[] {logEntry});
}
}
}
}