1using System.Diagnostics;
12 internal sealed
class LogService : ILogService
14 private const string startupCrashFileName =
"CrashDump.txt";
15 private string bareJid =
string.Empty;
16 private bool repairRequested =
false;
52 public void LogWarning(
string Message, params KeyValuePair<string, object?>[] Tags)
54 Log.
Warning(Message,
string.Empty, this.bareJid, [.. this.GetParameters(Tags)]);
61 public void LogException(Exception ex)
63 this.LogException(ex, []);
71 public void LogException(Exception ex, params KeyValuePair<string, object?>[] extraParameters)
75 Debug.WriteLine(ex.ToString());
76 Log.
Exception(ex,
string.Empty, this.bareJid, [.. this.GetParameters(extraParameters)]);
80 this.repairRequested =
true;
81 Task.Run(RestartForRepair);
90 public void LogAlert(
string Message, params KeyValuePair<string, object?>[] Tags)
92 Log.
Alert(Message,
string.Empty, this.bareJid, [.. this.GetParameters(Tags)]);
95 private static async Task RestartForRepair()
97 ServiceRef.StorageService.FlagForRepair();
99 await ServiceRef.UiService.DisplayAlert(ServiceRef.Localizer[nameof(AppResources.ErrorTitle)],
100 ServiceRef.Localizer[nameof(AppResources.RepairRestart)],
101 ServiceRef.Localizer[nameof(AppResources.Ok)]);
105 await ServiceRef.PlatformSpecific.CloseApplication();
118 public void SaveExceptionDump(
string Title,
string StackTrace)
123 string fileName = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), startupCrashFileName);
125 if (File.Exists(fileName))
126 contents = File.ReadAllText(fileName);
128 contents =
string.Empty;
130 File.WriteAllText(fileName, Title + Environment.NewLine + StackTrace + Environment.NewLine + contents);
137 public string LoadExceptionDump()
140 string fileName = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), startupCrashFileName);
142 if (File.Exists(fileName))
143 contents = File.ReadAllText(fileName);
145 contents =
string.Empty;
153 public void DeleteExceptionDump()
155 string fileName = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), startupCrashFileName);
157 if (File.Exists(fileName))
158 File.Delete(fileName);
166 public IList<KeyValuePair<string, object?>> GetParameters(params KeyValuePair<string, object?>[] Tags)
168 List<KeyValuePair<string, object?>> Result =
170 new KeyValuePair<string, object?>(
"Platform", DeviceInfo.Platform),
171 new KeyValuePair<string, object?>(
"RuntimeVersion", typeof(LogService).Assembly.ImageRuntimeVersion),
172 new KeyValuePair<string, object?>(
"AppVersion", AppInfo.VersionString),
173 new KeyValuePair<string, object?>(
"Manufacturer", DeviceInfo.Manufacturer),
174 new KeyValuePair<string, object?>(
"Device Model", DeviceInfo.Model),
175 new KeyValuePair<string, object?>(
"Device Name", DeviceInfo.Name),
176 new KeyValuePair<string, object?>(
"OS", DeviceInfo.VersionString),
177 new KeyValuePair<string, object?>(
"Platform", DeviceInfo.Platform.ToString()),
178 new KeyValuePair<string, object?>(
"Device Type", DeviceInfo.DeviceType.ToString()),
181 if (Tags is not
null)
182 Result.AddRange(Tags);
Base class for event sinks.
Filters incoming events and passes remaining events to a secondary event sink.
IEventSink SecondarySink
Secondary event sink receiving the events passing the filter.
Static class managing the application event log. Applications and services log events on this static ...
static string CleanStackTrace(string StackTrace)
Cleans a Stack Trace string, removing entries from the asynchronous execution model,...
static IEventSink[] Sinks
Registered sinks.
static void Register(IEventSink EventSink)
Registers an event sink with the event log. Call Unregister(IEventSink) to unregister it,...
static void Exception(Exception Exception, string Object, string Actor, string EventId, EventLevel Level, string Facility, string Module, params KeyValuePair< string, object >[] Tags)
Logs an exception. Event type will be determined by the severity of the exception.
static void Warning(string Message, string Object, string Actor, string EventId, EventLevel Level, string Facility, string Module, string StackTrace, params KeyValuePair< string, object >[] Tags)
Logs a warning event.
static Exception UnnestException(Exception Exception)
Unnests an exception, to extract the relevant inner exception.
static bool Unregister(IEventSink EventSink)
Unregisters an event sink from the event log.
static void Alert(string Message, string Object, string Actor, string EventId, EventLevel Level, string Facility, string Module, string StackTrace, params KeyValuePair< string, object >[] Tags)
Logs an alert event.
Event sink sending events to a destination over the XMPP network.
XmppClient Client
XMPP Client
Database inconsistency exception. Raised when an inconsistency in the database has been found.
Interface for all event sinks.