narsil/Tanshu.Accounts.Repository/QueryStore.cs

147 lines
3.7 KiB
C#
Raw Normal View History

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)
{
if (!Cache.Log) return;
if (message == null) return;
var msg = message.ToString();
if (_key != "NHibernate.SQL") return;
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)
{
if (!Cache.Log) return;
if (message == null || exception == null) return;
var msg = message.ToString();
if (_key != "NHibernate.SQL") return;
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);
}
}
}