Skip to content

Commit

Permalink
Added Discord.Net log messages to log4net logging
Browse files Browse the repository at this point in the history
  • Loading branch information
jallier committed Dec 7, 2016
1 parent c2f3906 commit e938ab1
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 17 deletions.
2 changes: 1 addition & 1 deletion DCBot/Initializer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class Initializer
public List<Audio> commands { get; } = new List<Audio>();
public string TOKEN { get; private set; }
public char CommandChar { get; private set; }
private static readonly ILog log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
private static readonly ILog log = LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
public Initializer()
{

Expand Down
25 changes: 9 additions & 16 deletions DCBot/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ static void Main(string[] args)

private bool audioPlaying = false; //This seems like a dirty hack.
private bool IsRunningOnMono { get; } = (Type.GetType("Mono.Runtime") != null);
private static readonly ILog log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); // Initialize logger with class name of calling class
private static readonly ILog log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); // Initialize logger with class name of calling class

DiscordClient _client = new DiscordClient(x => { x.LogLevel = LogSeverity.Info; });
/// <summary>
Expand All @@ -34,6 +34,12 @@ public void Start()
log.Info("Application is starting");
Initializer config = new Initializer().run();
Queue<Command> audioQueue = new Queue<Command>();
_client.Log.Message += (s, e) => // Log Discord.Net messages to log4net
{
if (e.Severity == LogSeverity.Info) { log.Info(e.Message); }
else if (e.Severity == LogSeverity.Warning) { log.Warn(e.Message); }
else if (e.Severity == LogSeverity.Error) { log.Error(e.Message); }
};

_client.UsingAudio(x => // Opens an AudioConfigBuilder so we can configure our AudioService
{
Expand Down Expand Up @@ -75,28 +81,15 @@ public void Start()
}
catch (Exception e) { log.Error(string.Format("{0}: {1}", e.GetType().ToString(), e.Message)); attempts++; }
}
if (attempts == 0)
{
log.Info("Connected");
}
else if (attempts == 3) //Failed to connect 3 times; check for errors in config file

if (attempts == 3) //Failed to connect 3 times; check for errors in config file
{
log.Warn("Failed to connect. Exiting");
Environment.Exit(1);
}
});
}

private static void closeLog(StreamWriter logfile)
{
logfile.Close();
}

private void logToFile(string message, StreamWriter logfile)
{

}

/// <summary>
/// Create a FileSystemWatcher to watch for changes in the config file to trigger a reload of the commands and audio
/// </summary>
Expand Down

0 comments on commit e938ab1

Please sign in to comment.