1
0
mirror of https://github.com/bitwarden/mobile synced 2025-12-05 23:53:33 +00:00
Files
mobile/src/Core/Services/Logging/DebugLogger.cs
Federico Maccaroni db7ca3b93e BEEEP: Abstract and Centralize Logging (#1663)
* Abstracted App Center Logging into its own component, so that we can have it centralized in one place and we avoid checking for FDroid on all the places we want to use it

* Implemented the new logger where Crashes.TrackError was being used except on some specific cases

* Improved logging, added a debug logger and removed AppCenter to be used on DEBUG
2022-03-02 14:15:16 -03:00

51 lines
1.4 KiB
C#

#if !FDROID
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Runtime.CompilerServices;
using Bit.Core.Abstractions;
namespace Bit.Core.Services
{
public class DebugLogger : ILogger
{
static ILogger _instance;
public static ILogger Instance
{
get
{
if (_instance is null)
{
_instance = new DebugLogger();
}
return _instance;
}
}
protected DebugLogger()
{
}
public void Error(string message, IDictionary<string, string> extraData = null, [CallerMemberName] string memberName = "", [CallerFilePath] string sourceFilePath = "", [CallerLineNumber] int sourceLineNumber = 0)
{
var classAndMethod = $"{Path.GetFileNameWithoutExtension(sourceFilePath)}.{memberName}";
var filePathAndLineNumber = $"{Path.GetFileName(sourceFilePath)}:{sourceLineNumber}";
if (string.IsNullOrEmpty(message))
{
Debug.WriteLine($"Error found in: {classAndMethod})");
return;
}
Debug.WriteLine($"File: {filePathAndLineNumber}");
Debug.WriteLine($"Method: {memberName}");
Debug.WriteLine($"Message: {message}");
}
public void Exception(Exception ex) => Debug.WriteLine(ex);
}
}
#endif