mirror of
https://github.com/Jetsparrow/karmabot.git
synced 2026-01-21 09:06:09 +03:00
Make logging accessible via perfusion
This commit is contained in:
parent
0a3d969bec
commit
08ebdbaa37
@ -1,5 +1,6 @@
|
||||
using JetKarmaBot.Commands;
|
||||
using NLog;
|
||||
using Perfusion;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
@ -11,7 +12,8 @@ namespace JetKarmaBot
|
||||
class ChatCommandRouter
|
||||
{
|
||||
User BotUser { get; }
|
||||
private static Logger log = LogManager.GetCurrentClassLogger();
|
||||
[Inject]
|
||||
private Logger log;
|
||||
|
||||
public ChatCommandRouter(User botUser)
|
||||
{
|
||||
|
||||
@ -13,7 +13,8 @@ namespace JetKarmaBot.Commands
|
||||
class AwardCommand : IChatCommand
|
||||
{
|
||||
public IReadOnlyCollection<string> Names => new[] { "award", "revoke" };
|
||||
private static Logger log = LogManager.GetCurrentClassLogger();
|
||||
[Inject]
|
||||
private Logger log;
|
||||
|
||||
public bool Execute(CommandString cmd, MessageEventArgs args)
|
||||
{
|
||||
|
||||
@ -10,7 +10,8 @@ namespace JetKarmaBot.Commands
|
||||
class LocaleCommand : IChatCommand
|
||||
{
|
||||
public IReadOnlyCollection<string> Names => new[] { "changelocale", "locale" };
|
||||
private static Logger log = LogManager.GetCurrentClassLogger();
|
||||
[Inject]
|
||||
private Logger log;
|
||||
|
||||
public bool Execute(CommandString cmd, MessageEventArgs args)
|
||||
{
|
||||
|
||||
@ -72,7 +72,7 @@ namespace JetKarmaBot
|
||||
|
||||
void InitCommands(Container c)
|
||||
{
|
||||
Commands = new ChatCommandRouter(Me);
|
||||
Commands = c.ResolveObject(new ChatCommandRouter(Me));
|
||||
Commands.Add(c.ResolveObject(new StartCommand()));
|
||||
Commands.Add(c.ResolveObject(new AwardCommand(Me)));
|
||||
Commands.Add(c.ResolveObject(new StatusCommand()));
|
||||
|
||||
@ -29,6 +29,7 @@ namespace JetKarmaBot
|
||||
var dbOptions = new DbContextOptionsBuilder<KarmaContext>()
|
||||
.UseMySql(cfg.ConnectionString);
|
||||
|
||||
c.AddInfo<Logger>(new LogInfo());
|
||||
c.AddTransient(() => new KarmaContext(dbOptions.Options));
|
||||
c.Add<JetKarmaBot>();
|
||||
|
||||
|
||||
@ -13,8 +13,9 @@ namespace JetKarmaBot
|
||||
private Dictionary<string, Locale> locales = new Dictionary<string, Locale>();
|
||||
|
||||
[Inject]
|
||||
public Localization()
|
||||
public Localization(Container c)
|
||||
{
|
||||
c.ResolveObject(this);
|
||||
log.Info("Initializing...");
|
||||
string langsFolder = "lang";
|
||||
if (!Directory.Exists(langsFolder))
|
||||
@ -51,7 +52,8 @@ namespace JetKarmaBot
|
||||
}
|
||||
}
|
||||
|
||||
private static Logger log = LogManager.GetCurrentClassLogger();
|
||||
[Inject]
|
||||
private Logger log;
|
||||
|
||||
public Locale FindByCommonName(string name)
|
||||
{
|
||||
|
||||
20
JetKarmaBot/Services/LogInfo.cs
Normal file
20
JetKarmaBot/Services/LogInfo.cs
Normal file
@ -0,0 +1,20 @@
|
||||
using System;
|
||||
using System.Linq;
|
||||
using NLog;
|
||||
using Perfusion;
|
||||
|
||||
namespace JetKarmaBot
|
||||
{
|
||||
public class LogInfo : ObjectInfo
|
||||
{
|
||||
public override object GetInstance(Type requester = null)
|
||||
{
|
||||
return LogManager.GetLogger(requester != null ? getTypeName(requester) : "<type unspecified>");
|
||||
}
|
||||
private string getTypeName(Type t)
|
||||
{
|
||||
return (t.DeclaringType == null ? t.Namespace + "." + t.Name : getTypeName(t.DeclaringType) + "." + t.Name)
|
||||
+ (t.GenericTypeArguments.Length > 0 ? "<" + string.Join(",", t.GenericTypeArguments.Select(getTypeName)) + ">" : "");
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1 +1 @@
|
||||
Subproject commit a806f4d9fb9eb0e3036567304cabe1adf65d476c
|
||||
Subproject commit a9503a6b2cfa9166d4904ad995bc81d39ec9b2b7
|
||||
Loading…
Reference in New Issue
Block a user