2014-11-02 08:03:31 +00:00
|
|
|
|
using System;
|
|
|
|
|
using System.Diagnostics;
|
|
|
|
|
using NHibernate;
|
|
|
|
|
using NHibernate.SqlCommand;
|
|
|
|
|
|
|
|
|
|
namespace Tanshu.Accounts.Repository
|
|
|
|
|
{
|
|
|
|
|
// Add the following in app settings in the config file to enable logging
|
|
|
|
|
//<add key="nhibernate-logger" value="Tanshu.Accounts.Repository.EventsLogFactory, Tanshu.Accounts.Repository"/>
|
|
|
|
|
public class EventsLogger : IInternalLogger
|
|
|
|
|
{
|
|
|
|
|
private readonly string _key;
|
|
|
|
|
public EventsLogger(string key)
|
|
|
|
|
{
|
|
|
|
|
_key = key;
|
|
|
|
|
}
|
|
|
|
|
public bool IsDebugEnabled
|
|
|
|
|
{
|
|
|
|
|
get { return true; }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public bool IsErrorEnabled
|
|
|
|
|
{
|
|
|
|
|
get { return true; }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public bool IsFatalEnabled
|
|
|
|
|
{
|
|
|
|
|
get { return true; }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public bool IsInfoEnabled
|
|
|
|
|
{
|
|
|
|
|
get { return true; }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public bool IsWarnEnabled
|
|
|
|
|
{
|
|
|
|
|
get { return true; }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#region Methods (14)
|
|
|
|
|
|
|
|
|
|
// Public Methods (14)
|
|
|
|
|
|
|
|
|
|
public void Debug(object message)
|
|
|
|
|
{
|
2014-11-06 10:39:11 +00:00
|
|
|
|
if (!Cache.Log) return;
|
2014-11-02 08:03:31 +00:00
|
|
|
|
if (message == null) return;
|
|
|
|
|
var msg = message.ToString();
|
2014-11-06 10:39:11 +00:00
|
|
|
|
if (_key != "NHibernate.SQL") return;
|
2014-11-02 08:03:31 +00:00
|
|
|
|
Console.WriteLine(string.Format(" -- {0} ---+ {1} +---", _key, DateTime.Now.ToString("MM/dd/yyyy hh:mm:ss.ff")));
|
|
|
|
|
Console.WriteLine(message.ToString().Trim());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void Debug(object message, Exception exception)
|
|
|
|
|
{
|
2014-11-06 10:39:11 +00:00
|
|
|
|
if (!Cache.Log) return;
|
2014-11-02 08:03:31 +00:00
|
|
|
|
if (message == null || exception == null) return;
|
|
|
|
|
var msg = message.ToString();
|
2014-11-06 10:39:11 +00:00
|
|
|
|
if (_key != "NHibernate.SQL") return;
|
2014-11-02 08:03:31 +00:00
|
|
|
|
Console.WriteLine(string.Format(" -- {0} ---+ {1} +---", _key, DateTime.Now.ToString("MM/dd/yyyy hh:mm:ss.ff")));
|
|
|
|
|
Console.WriteLine(message.ToString().Trim());
|
|
|
|
|
Console.WriteLine(exception.ToString());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void DebugFormat(string format, params object[] args)
|
|
|
|
|
{
|
|
|
|
|
Console.Write(new[]
|
|
|
|
|
{
|
|
|
|
|
string.Format("---+ {0} +---", DateTime.Now.ToString("MM/dd/yyyy hh:mm:ss.ff")),
|
|
|
|
|
string.Format(format, args),
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void Error(object message)
|
|
|
|
|
{
|
|
|
|
|
Debug(message);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void Error(object message, Exception exception)
|
|
|
|
|
{
|
|
|
|
|
Debug(message, exception);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void ErrorFormat(string format, params object[] args)
|
|
|
|
|
{
|
|
|
|
|
DebugFormat(format, args);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void Fatal(object message)
|
|
|
|
|
{
|
|
|
|
|
Debug(message);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void Fatal(object message, Exception exception)
|
|
|
|
|
{
|
|
|
|
|
Debug(message, exception);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void Info(object message)
|
|
|
|
|
{
|
|
|
|
|
Debug(message);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void Info(object message, Exception exception)
|
|
|
|
|
{
|
|
|
|
|
Debug(message, exception);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void InfoFormat(string format, params object[] args)
|
|
|
|
|
{
|
|
|
|
|
DebugFormat(format, args);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void Warn(object message)
|
|
|
|
|
{
|
|
|
|
|
Debug(message);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void Warn(object message, Exception exception)
|
|
|
|
|
{
|
|
|
|
|
Debug(message, exception);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void WarnFormat(string format, params object[] args)
|
|
|
|
|
{
|
|
|
|
|
DebugFormat(format, args);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endregion Methods
|
|
|
|
|
}
|
|
|
|
|
public class EventsLogFactory : ILoggerFactory
|
|
|
|
|
{
|
|
|
|
|
public IInternalLogger LoggerFor(Type type)
|
|
|
|
|
{
|
|
|
|
|
return new EventsLogger(type.ToString());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public IInternalLogger LoggerFor(string keyName)
|
|
|
|
|
{
|
|
|
|
|
return new EventsLogger(keyName);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|