2022-11-24 22:37:24 +01:00
|
|
|
using System.Diagnostics;
|
2022-12-12 15:08:00 +01:00
|
|
|
using System.Reflection;
|
2022-11-24 22:37:24 +01:00
|
|
|
|
|
|
|
|
namespace CommonHelpers
|
|
|
|
|
{
|
|
|
|
|
public static class Log
|
|
|
|
|
{
|
2022-12-15 21:34:51 +01:00
|
|
|
#if PRODUCTION_BUILD
|
|
|
|
|
internal static String SENTRY_DSN = "https://3c93e3c3b47b40ffba72d9cb333fc6d7@o4504334913830912.ingest.sentry.io/4504334914879488";
|
|
|
|
|
#else
|
2022-12-16 11:29:39 +01:00
|
|
|
internal static String SENTRY_DSN = "https://331e3316a2ba45dcae505791810a47a6@glitchtip.ayufan.dev/2";
|
2022-12-15 21:34:51 +01:00
|
|
|
#endif
|
2022-12-12 15:08:00 +01:00
|
|
|
|
2022-11-28 11:04:53 +01:00
|
|
|
#if DEBUG
|
|
|
|
|
private static bool LogToTrace = true;
|
|
|
|
|
#else
|
|
|
|
|
private static bool LogToTrace = false;
|
|
|
|
|
#endif
|
|
|
|
|
private static bool LogToConsole = Environment.UserInteractive;
|
|
|
|
|
|
2022-12-12 15:08:00 +01:00
|
|
|
internal static void SentryOptions(Sentry.SentryOptions o)
|
|
|
|
|
{
|
2022-12-15 21:46:33 +01:00
|
|
|
var env = Instance.IsProductionBuild ? "prod" : "dev";
|
2022-12-12 20:03:15 +01:00
|
|
|
var build = Instance.IsDEBUG ? "debug" : "release";
|
2022-12-15 21:46:33 +01:00
|
|
|
var deploy = File.Exists("Uninstaller.exe") ? "setup" : "zip";
|
2022-12-12 20:03:15 +01:00
|
|
|
|
2022-12-12 15:08:00 +01:00
|
|
|
o.Dsn = Log.SENTRY_DSN;
|
|
|
|
|
o.TracesSampleRate = 1.0;
|
|
|
|
|
o.IsGlobalModeEnabled = true;
|
2022-12-15 21:46:33 +01:00
|
|
|
o.Environment = String.Format("{0}:{1}_{2}", Instance.ApplicationName, build, deploy);
|
2022-12-12 20:03:15 +01:00
|
|
|
o.DefaultTags.Add("App", Instance.ApplicationName);
|
2022-12-12 15:08:00 +01:00
|
|
|
o.DefaultTags.Add("MachineID", Instance.MachineID);
|
2022-12-15 21:46:33 +01:00
|
|
|
o.DefaultTags.Add("Build", build);
|
|
|
|
|
o.DefaultTags.Add("Deploy", deploy);
|
2022-12-12 15:08:00 +01:00
|
|
|
|
|
|
|
|
var releaseVersion = typeof(Log).Assembly.GetCustomAttributes<AssemblyInformationalVersionAttribute>().FirstOrDefault();
|
|
|
|
|
if (releaseVersion is not null)
|
|
|
|
|
{
|
|
|
|
|
o.Release = releaseVersion.InformationalVersion;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-11-24 22:37:24 +01:00
|
|
|
public static void TraceLine(string format, params object?[] arg)
|
|
|
|
|
{
|
2022-11-28 11:04:53 +01:00
|
|
|
if (!LogToTrace && !LogToConsole)
|
|
|
|
|
return;
|
2022-11-24 22:37:24 +01:00
|
|
|
|
2022-11-28 11:04:53 +01:00
|
|
|
String line = string.Format(format, arg);
|
|
|
|
|
if (LogToTrace)
|
|
|
|
|
Trace.WriteLine(line);
|
|
|
|
|
if (LogToConsole)
|
2022-11-24 22:37:24 +01:00
|
|
|
Console.WriteLine(line);
|
|
|
|
|
}
|
2022-12-12 15:08:00 +01:00
|
|
|
|
2022-12-14 11:48:02 +01:00
|
|
|
public static void TraceError(string format, params object?[] arg)
|
|
|
|
|
{
|
|
|
|
|
String line = string.Format(format, arg);
|
|
|
|
|
Sentry.SentrySdk.CaptureMessage(line, Sentry.SentryLevel.Error);
|
|
|
|
|
if (LogToTrace)
|
|
|
|
|
Trace.WriteLine(line);
|
|
|
|
|
if (LogToConsole)
|
|
|
|
|
Console.WriteLine(line);
|
|
|
|
|
}
|
|
|
|
|
|
2022-12-12 18:44:02 +01:00
|
|
|
public static void TraceException(String type, Object? name, Exception e)
|
|
|
|
|
{
|
|
|
|
|
TraceLine("{0}: {1}: Exception: {2}", type, name, e);
|
|
|
|
|
Sentry.SentrySdk.CaptureException(e, scope =>
|
|
|
|
|
{
|
|
|
|
|
scope.SetTag("type", type);
|
|
|
|
|
scope.SetTag("name", name?.ToString() ?? "null");
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2022-12-12 15:08:00 +01:00
|
|
|
public static void TraceException(String type, Exception e)
|
|
|
|
|
{
|
|
|
|
|
TraceLine("{0}: Exception: {1}", type, e);
|
|
|
|
|
Sentry.SentrySdk.CaptureException(e, scope =>
|
|
|
|
|
{
|
|
|
|
|
scope.SetTag("type", type);
|
|
|
|
|
});
|
|
|
|
|
}
|
2022-11-24 22:37:24 +01:00
|
|
|
}
|
|
|
|
|
}
|