2015-11-11 08:42:49 +08:00
|
|
|
|
using System.Diagnostics;
|
|
|
|
|
using NLog;
|
2015-11-09 11:59:20 +08:00
|
|
|
|
using Wox.Infrastructure.Exception;
|
2013-12-20 19:38:10 +08:00
|
|
|
|
|
2014-09-19 16:57:48 +08:00
|
|
|
|
namespace Wox.Infrastructure.Logger
|
2013-12-20 19:38:10 +08:00
|
|
|
|
{
|
|
|
|
|
public class Log
|
|
|
|
|
{
|
2015-01-20 22:33:45 +08:00
|
|
|
|
private static NLog.Logger logger = LogManager.GetCurrentClassLogger();
|
2013-12-20 19:38:10 +08:00
|
|
|
|
|
2015-11-09 09:32:33 +08:00
|
|
|
|
public static void Error(System.Exception e)
|
2015-01-11 21:52:30 +08:00
|
|
|
|
{
|
2015-11-08 01:32:58 +08:00
|
|
|
|
#if DEBUG
|
|
|
|
|
throw e;
|
|
|
|
|
#else
|
2015-11-11 08:42:49 +08:00
|
|
|
|
while (e.InnerException != null)
|
|
|
|
|
{
|
|
|
|
|
logger.Error(e.Message);
|
|
|
|
|
logger.Error(e.StackTrace);
|
|
|
|
|
e = e.InnerException;
|
|
|
|
|
}
|
2015-11-08 01:32:58 +08:00
|
|
|
|
#endif
|
2015-01-11 21:52:30 +08:00
|
|
|
|
}
|
|
|
|
|
|
2014-03-23 17:43:46 +08:00
|
|
|
|
public static void Debug(string msg)
|
|
|
|
|
{
|
2015-11-08 01:32:58 +08:00
|
|
|
|
System.Diagnostics.Debug.WriteLine($"DEBUG: {msg}");
|
2015-01-20 22:33:45 +08:00
|
|
|
|
logger.Debug(msg);
|
2014-03-23 17:43:46 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static void Info(string msg)
|
|
|
|
|
{
|
2015-11-08 01:32:58 +08:00
|
|
|
|
System.Diagnostics.Debug.WriteLine($"INFO: {msg}");
|
2015-01-20 22:33:45 +08:00
|
|
|
|
logger.Info(msg);
|
2014-03-23 17:43:46 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static void Warn(string msg)
|
|
|
|
|
{
|
2015-11-08 01:32:58 +08:00
|
|
|
|
System.Diagnostics.Debug.WriteLine($"WARN: {msg}");
|
2015-01-20 22:33:45 +08:00
|
|
|
|
logger.Warn(msg);
|
2014-03-23 17:43:46 +08:00
|
|
|
|
}
|
|
|
|
|
|
2015-11-09 09:32:33 +08:00
|
|
|
|
public static void Fatal(System.Exception e)
|
2014-03-23 17:43:46 +08:00
|
|
|
|
{
|
2015-11-08 01:32:58 +08:00
|
|
|
|
#if DEBUG
|
|
|
|
|
throw e;
|
|
|
|
|
#else
|
|
|
|
|
logger.Fatal(ExceptionFormatter.FormatExcpetion(e));
|
|
|
|
|
#endif
|
2014-03-23 17:43:46 +08:00
|
|
|
|
}
|
2013-12-20 19:38:10 +08:00
|
|
|
|
}
|
|
|
|
|
}
|