Official FA .NET logger package
- Logging: For general logging purpose
- Notify: For general notify purpose
- Inject logger
public static void SetupLogger(IServiceCollection serviceProvider, IConfiguration configuration)
{
var consoleLoggerProvider = new ConsoleLoggerProvider();
// discord
var discordUrl = configuration.GetValue<string>("AuthSettings:DiscordURI");
// telegram
var telegramBotToken = configuration.GetValue<string>("AppSettings:TelegramBotToken");
var telegramGroupId = configuration.GetValue<string>("AppSettings:TelegramGroupId");
serviceProvider.AddSingleton<IMyLogger, MyLogger>(s =>
{
var list = new List<IMyLoggerProvider>
{
consoleLoggerProvider,
};
// discord
if (!string.IsNullOrWhiteSpace(discordUrl))
{
list.Add(new DiscordLoggerProvider(discordUrl));
}
// telegram
if (!string.IsNullOrWhiteSpace(telegramBotToken) && !string.IsNullOrWhiteSpace(telegramGroupId))
{
list.Add(new TelegramLoggerProvider(telegramBotToken, telegramGroupId));
}
return new MyLogger(list);
});
}
- Use logger
//info
await myLogger.LogInfo("This is done");
// error
await myLogger.LogException(ex, $"Date: {date}", ex.StackTrace);
// notification
await myLogger.LogNotification($"Distributor Publisher\nDate: {dateTime} done");
- Discord Logger
services.AddHttpClient<IMyLoggerProvider, DiscordMyLoggerProvider>(c =>
{
c.BaseAddress = new Uri(context.Configuration.GetValue<string>("AuthSettings:DiscordURI"));
});
services.AddSingleton<IMyLogger>(s => new MyLogger(s.GetRequiredService<IMyLoggerProvider>()));
- Fork it
- Create your feature branch (git checkout -b my-new-feature)
- Commit your changes (git commit -m 'Add some feature')
- Push to the branch (git push origin my-new-feature)
- Create new Pull Request