Skip to content

Commit 5384f31

Browse files
committed
feat(misc): refactor code
Signed-off-by: Ayush P Gupta <[email protected]>
1 parent ab6f54b commit 5384f31

9 files changed

+68
-17
lines changed

.idea/.idea.FA.Logger/.idea/conventionalCommit.xml

+5
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

FA.Logger/IMyLogger.cs

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
namespace FA.Logger;
2+
3+
public interface IMyLogger
4+
{
5+
public Task Log(Exception ex, string data = "", string? stackTrace = "", string? subtitle = null);
6+
}

FA.Logger/IMyNotifier.cs

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
namespace FA.Logger;
2+
3+
public interface IMyNotifier
4+
{
5+
public void Notify(string message);
6+
}

FA.Logger/MyLogger.cs

+6-11
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@
22

33
namespace FA.Logger
44
{
5-
public class MyLogger
5+
public class MyLogger : IMyLogger
66
{
7-
private readonly IDiscordLogger _discordLogger;
7+
private readonly IMyLoggerProvider _myLoggerProvider;
88

9-
public MyLogger(IDiscordLogger discordLogger)
9+
public MyLogger(IMyLoggerProvider myLoggerProvider)
1010
{
11-
_discordLogger = discordLogger;
11+
_myLoggerProvider = myLoggerProvider;
1212
}
1313

1414
/// <summary>
@@ -20,7 +20,7 @@ public MyLogger(IDiscordLogger discordLogger)
2020
/// <param name="data">The string representing payload data</param>
2121
/// <param name="stackTrace"></param>
2222
/// <param name="subtitle">An optional subtitle to be logged</param>
23-
public async Task CreateLog(Exception ex, string data = "", string? stackTrace = "", string? subtitle = null)
23+
public async Task Log(Exception ex, string data = "", string? stackTrace = "", string? subtitle = null)
2424
{
2525
try
2626
{
@@ -58,12 +58,7 @@ private async Task LogToDiscord(Exception ex, string data, string? stackTrace, s
5858
finalMsg = $"{finalMsg}----StackTrace END----\n";
5959
}
6060

61-
await _discordLogger.SaveLog(finalMsg);
61+
await _myLoggerProvider.SaveLog(finalMsg);
6262
}
63-
64-
//public async void LogToTelegram(string message)
65-
//{
66-
// await _telegramLogger.Log(message);
67-
//}
6863
}
6964
}

FA.Logger/MyNotifier.cs

+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
using FA.Logger.Clients;
2+
3+
namespace FA.Logger
4+
{
5+
public class MyNotifier : IMyNotifier
6+
{
7+
private readonly INotifyProvider _notifyProvider;
8+
9+
public MyNotifier(INotifyProvider notifyProvider)
10+
{
11+
_notifyProvider = notifyProvider;
12+
}
13+
14+
/// <summary>
15+
/// Notify message
16+
/// </summary>
17+
/// <param name="message"></param>
18+
/// <exception cref="NullReferenceException"></exception>
19+
public async void Notify(string message)
20+
{
21+
try
22+
{
23+
if (_notifyProvider != null)
24+
{
25+
await _notifyProvider.Log(message);
26+
}
27+
else
28+
{
29+
throw new NullReferenceException();
30+
}
31+
}
32+
catch (Exception e)
33+
{
34+
Console.Error.WriteLine(e);
35+
throw;
36+
}
37+
}
38+
}
39+
}

FA.Logger/Clients/IDiscordLogger.cs FA.Logger/Providers/Base/IMyLoggerProvider.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
namespace FA.Logger.Clients
22
{
3-
public interface IDiscordLogger
3+
public interface IMyLoggerProvider
44
{
55
/// <summary>
66
/// Logs to discord

FA.Logger/Clients/ITelegramLogger.cs FA.Logger/Providers/Base/INotifyProvider.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
namespace FA.Logger.Clients
22
{
3-
public interface ITelegramLogger
3+
public interface INotifyProvider
44
{
55
/// <summary>
66
/// Creates log and sends to telegram

FA.Logger/Clients/DiscordLogger.cs FA.Logger/Providers/DiscordMyLoggerProvider.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
namespace FA.Logger.Clients
22
{
3-
public class DiscordLogger : IDiscordLogger
3+
public class DiscordMyLoggerProvider : IMyLoggerProvider
44
{
55
private readonly HttpClient _httpClient;
66

7-
public DiscordLogger(HttpClient httpClient)
7+
public DiscordMyLoggerProvider(HttpClient httpClient)
88
{
99
_httpClient = httpClient;
1010
}

FA.Logger/Clients/TelegramLogger.cs FA.Logger/Providers/TelegramNotifyProvider.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@
22

33
namespace FA.Logger.Clients
44
{
5-
public class TelegramLogger : ITelegramLogger
5+
public class TelegramNotifyProvider : INotifyProvider
66
{
77
private readonly HttpClient _httpClient;
88
private readonly string _botToken;
99
private readonly string _groupId;
1010

11-
public TelegramLogger(string botToken, string groupId)
11+
public TelegramNotifyProvider(string botToken, string groupId)
1212
{
1313
_botToken = botToken;
1414
_groupId = groupId;

0 commit comments

Comments
 (0)