removed Common.Logging.Log4Net.dll from global shared libs

removed ILog dependency from Spring.Aop.Tests
added Spring.Data.NHibernate20.Tests and Spring.Data.NHibernate21.Tests to grand solution
removed log4net assembly from global shared lib folder
This commit is contained in:
eeichinger
2009-01-15 21:45:23 +00:00
parent d88e86de9b
commit f75552c02c
11 changed files with 290 additions and 452 deletions

View File

@@ -5,206 +5,211 @@ using System.Collections;
using System.Globalization;
using System.Text;
using Common.Logging;
using Common.Logging.Simple;
namespace Spring.Aspects.Exceptions
{
public class CaptureOutputLogger : ILog
public class CaptureOutputLogger : TraceLogger
{
public static readonly string NAME = "capturingLogger";
private LogLevel _currentLogLevel = LogLevel.All;
public CaptureOutputLogger()
: base(NAME, LogLevel.All, false, false, null)
{}
private IList logMessages = new ArrayList();
public IList LogMessages
{
get { return logMessages; }
set { logMessages = value; }
}
/// <summary>
/// Do the actual logging by constructing the log message using a <see cref="StringBuilder" /> then
/// sending the output to <see cref="Console.Out" />.
/// </summary>
/// <param name="level">The <see cref="LogLevel" /> of the message.</param>
/// <param name="message">The log message.</param>
/// <param name="e">An optional <see cref="Exception" /> associated with the message.</param>
private void Write(LogLevel level, object message, Exception e)
{
// Use a StringBuilder for better performance
StringBuilder sb = new StringBuilder();
// Append date-time if so configured
// Append a readable representation of the log level
sb.Append(("[" + level.ToString().ToUpper() + "]").PadRight(8));
// Append the message
sb.Append(message);
// Append stack trace if not null
if (e != null)
{
sb.Append(Environment.NewLine).Append(e.ToString());
}
// Print to the appropriate destination
logMessages.Add(sb.ToString());
}
/// <summary>
/// Determines if the given log level is currently enabled.
/// </summary>
/// <param name="level"></param>
/// <returns></returns>
private bool IsLevelEnabled(LogLevel level)
{
int iLevel = (int)level;
int iCurrentLogLevel = (int)_currentLogLevel;
// return iLevel.CompareTo(iCurrentLogLevel); better ???
return (iLevel >= iCurrentLogLevel);
}
#region ILog Members
public void Trace(object message)
{
Trace(message, null);
}
public void Trace(object message, Exception e)
{
if (IsLevelEnabled(LogLevel.Trace))
{
Write(LogLevel.Trace, message, e);
}
}
public void Debug(object message)
{
Debug(message, null);
}
public void Debug(object message, Exception e)
{
if (IsLevelEnabled(LogLevel.Debug))
{
Write(LogLevel.Debug, message, e);
}
}
public void Error(object message)
{
Error(message, null);
}
public void Error(object message, Exception e)
{
if (IsLevelEnabled(LogLevel.Error))
{
Write(LogLevel.Error, message, e);
}
}
public void Fatal(object message)
{
Fatal(message, null);
}
public void Fatal(object message, Exception e)
{
if (IsLevelEnabled(LogLevel.Fatal))
{
Write(LogLevel.Fatal, message, e);
}
}
public void Info(object message)
{
Info(message, null);
}
public void Info(object message, Exception e)
{
if (IsLevelEnabled(LogLevel.Info))
{
Write(LogLevel.Info, message, e);
}
}
public void Warn(object message)
{
Warn(message, null);
}
public void Warn(object message, Exception e)
{
if (IsLevelEnabled(LogLevel.Warn))
{
Write(LogLevel.Warn, message, e);
}
}
/// <summary>
/// Returns <see langword="true" /> if the current <see cref="LogLevel" /> is greater than or
/// equal to <see cref="LogLevel.Trace" />. If it is, all messages will be sent to <see cref="Console.Out" />.
/// </summary>
public bool IsTraceEnabled
{
get { return IsLevelEnabled(LogLevel.Trace); }
}
/// <summary>
/// Returns <see langword="true" /> if the current <see cref="LogLevel" /> is greater than or
/// equal to <see cref="LogLevel.Debug" />. If it is, all messages will be sent to <see cref="Console.Out" />.
/// </summary>
public bool IsDebugEnabled
{
get { return IsLevelEnabled(LogLevel.Debug); }
}
/// <summary>
/// Returns <see langword="true" /> if the current <see cref="LogLevel" /> is greater than or
/// equal to <see cref="LogLevel.Error" />. If it is, only messages with a <see cref="LogLevel" /> of
/// <see cref="LogLevel.Error" /> and <see cref="LogLevel.Fatal" /> will be sent to <see cref="Console.Out" />.
/// </summary>
public bool IsErrorEnabled
{
get { return IsLevelEnabled(LogLevel.Error); }
}
/// <summary>
/// Returns <see langword="true" /> if the current <see cref="LogLevel" /> is greater than or
/// equal to <see cref="LogLevel.Fatal" />. If it is, only messages with a <see cref="LogLevel" /> of
/// <see cref="LogLevel.Fatal" /> will be sent to <see cref="Console.Out" />.
/// </summary>
public bool IsFatalEnabled
{
get { return IsLevelEnabled(LogLevel.Fatal); }
}
/// <summary>
/// Returns <see langword="true" /> if the current <see cref="LogLevel" /> is greater than or
/// equal to <see cref="LogLevel.Info" />. If it is, only messages with a <see cref="LogLevel" /> of
/// <see cref="LogLevel.Info" />, <see cref="LogLevel.Warn" />, <see cref="LogLevel.Error" />, and
/// <see cref="LogLevel.Fatal" /> will be sent to <see cref="Console.Out" />.
/// </summary>
public bool IsInfoEnabled
{
get { return IsLevelEnabled(LogLevel.Info); }
}
/// <summary>
/// Returns <see langword="true" /> if the current <see cref="LogLevel" /> is greater than or
/// equal to <see cref="LogLevel.Warn" />. If it is, only messages with a <see cref="LogLevel" /> of
/// <see cref="LogLevel.Warn" />, <see cref="LogLevel.Error" />, and <see cref="LogLevel.Fatal" />
/// will be sent to <see cref="Console.Out" />.
/// </summary>
public bool IsWarnEnabled
{
get { return IsLevelEnabled(LogLevel.Warn); }
}
#endregion
// private LogLevel _currentLogLevel = LogLevel.All;
//
// private IList logMessages = new ArrayList();
//
// public IList LogMessages
// {
// get { return logMessages; }
// set { logMessages = value; }
// }
//
// /// <summary>
// /// Do the actual logging by constructing the log message using a <see cref="StringBuilder" /> then
// /// sending the output to <see cref="Console.Out" />.
// /// </summary>
// /// <param name="level">The <see cref="LogLevel" /> of the message.</param>
// /// <param name="message">The log message.</param>
// /// <param name="e">An optional <see cref="Exception" /> associated with the message.</param>
// private void Write(LogLevel level, object message, Exception e)
// {
// // Use a StringBuilder for better performance
// StringBuilder sb = new StringBuilder();
// // Append date-time if so configured
// // Append a readable representation of the log level
// sb.Append(("[" + level.ToString().ToUpper() + "]").PadRight(8));
//
// // Append the message
// sb.Append(message);
//
// // Append stack trace if not null
// if (e != null)
// {
// sb.Append(Environment.NewLine).Append(e.ToString());
// }
//
// // Print to the appropriate destination
// logMessages.Add(sb.ToString());
// }
//
// /// <summary>
// /// Determines if the given log level is currently enabled.
// /// </summary>
// /// <param name="level"></param>
// /// <returns></returns>
// private bool IsLevelEnabled(LogLevel level)
// {
// int iLevel = (int)level;
// int iCurrentLogLevel = (int)_currentLogLevel;
//
// // return iLevel.CompareTo(iCurrentLogLevel); better ???
// return (iLevel >= iCurrentLogLevel);
// }
//
// #region ILog Members
//
// public void Trace(object message)
// {
// Trace(message, null);
// }
//
// public void Trace(object message, Exception e)
// {
// if (IsLevelEnabled(LogLevel.Trace))
// {
// Write(LogLevel.Trace, message, e);
// }
// }
//
// public void Debug(object message)
// {
// Debug(message, null);
// }
//
// public void Debug(object message, Exception e)
// {
// if (IsLevelEnabled(LogLevel.Debug))
// {
// Write(LogLevel.Debug, message, e);
// }
// }
//
// public void Error(object message)
// {
// Error(message, null);
// }
//
// public void Error(object message, Exception e)
// {
// if (IsLevelEnabled(LogLevel.Error))
// {
// Write(LogLevel.Error, message, e);
// }
// }
//
// public void Fatal(object message)
// {
// Fatal(message, null);
// }
//
// public void Fatal(object message, Exception e)
// {
// if (IsLevelEnabled(LogLevel.Fatal))
// {
// Write(LogLevel.Fatal, message, e);
// }
// }
//
// public void Info(object message)
// {
// Info(message, null);
// }
//
// public void Info(object message, Exception e)
// {
// if (IsLevelEnabled(LogLevel.Info))
// {
// Write(LogLevel.Info, message, e);
// }
// }
//
// public void Warn(object message)
// {
// Warn(message, null);
// }
//
// public void Warn(object message, Exception e)
// {
// if (IsLevelEnabled(LogLevel.Warn))
// {
// Write(LogLevel.Warn, message, e);
// }
// }
//
// /// <summary>
// /// Returns <see langword="true" /> if the current <see cref="LogLevel" /> is greater than or
// /// equal to <see cref="LogLevel.Trace" />. If it is, all messages will be sent to <see cref="Console.Out" />.
// /// </summary>
// public bool IsTraceEnabled
// {
// get { return IsLevelEnabled(LogLevel.Trace); }
// }
//
// /// <summary>
// /// Returns <see langword="true" /> if the current <see cref="LogLevel" /> is greater than or
// /// equal to <see cref="LogLevel.Debug" />. If it is, all messages will be sent to <see cref="Console.Out" />.
// /// </summary>
// public bool IsDebugEnabled
// {
// get { return IsLevelEnabled(LogLevel.Debug); }
// }
//
// /// <summary>
// /// Returns <see langword="true" /> if the current <see cref="LogLevel" /> is greater than or
// /// equal to <see cref="LogLevel.Error" />. If it is, only messages with a <see cref="LogLevel" /> of
// /// <see cref="LogLevel.Error" /> and <see cref="LogLevel.Fatal" /> will be sent to <see cref="Console.Out" />.
// /// </summary>
// public bool IsErrorEnabled
// {
// get { return IsLevelEnabled(LogLevel.Error); }
// }
//
// /// <summary>
// /// Returns <see langword="true" /> if the current <see cref="LogLevel" /> is greater than or
// /// equal to <see cref="LogLevel.Fatal" />. If it is, only messages with a <see cref="LogLevel" /> of
// /// <see cref="LogLevel.Fatal" /> will be sent to <see cref="Console.Out" />.
// /// </summary>
// public bool IsFatalEnabled
// {
// get { return IsLevelEnabled(LogLevel.Fatal); }
// }
//
// /// <summary>
// /// Returns <see langword="true" /> if the current <see cref="LogLevel" /> is greater than or
// /// equal to <see cref="LogLevel.Info" />. If it is, only messages with a <see cref="LogLevel" /> of
// /// <see cref="LogLevel.Info" />, <see cref="LogLevel.Warn" />, <see cref="LogLevel.Error" />, and
// /// <see cref="LogLevel.Fatal" /> will be sent to <see cref="Console.Out" />.
// /// </summary>
// public bool IsInfoEnabled
// {
// get { return IsLevelEnabled(LogLevel.Info); }
// }
//
//
// /// <summary>
// /// Returns <see langword="true" /> if the current <see cref="LogLevel" /> is greater than or
// /// equal to <see cref="LogLevel.Warn" />. If it is, only messages with a <see cref="LogLevel" /> of
// /// <see cref="LogLevel.Warn" />, <see cref="LogLevel.Error" />, and <see cref="LogLevel.Fatal" />
// /// will be sent to <see cref="Console.Out" />.
// /// </summary>
// public bool IsWarnEnabled
// {
// get { return IsLevelEnabled(LogLevel.Warn); }
// }
//
// #endregion
}
}

View File

@@ -1,27 +1,55 @@
using System;
using System.Collections;
using System.Collections.Specialized;
using System.Diagnostics;
using Common.Logging;
using Common.Logging.Simple;
namespace Spring.Aspects.Exceptions
{
public class CaptureOutputLoggerFactoryAdapter : ILoggerFactoryAdapter
public class CaptureOutputLoggerFactoryAdapter : ILoggerFactoryAdapter, IDisposable
{
private CaptureOutputLogger adviceLogger;
private class CapturingTraceListener : TraceListener
{
private readonly CaptureOutputLoggerFactoryAdapter adapter;
public CapturingTraceListener(CaptureOutputLoggerFactoryAdapter adapter)
{
this.adapter = adapter;
}
public override void Write(string message)
{
adapter.LogMessages.Add(message);
}
public override void WriteLine(string message)
{
this.Write(message);
}
}
private readonly CapturingTraceListener listener;
public CaptureOutputLoggerFactoryAdapter()
{
listener = new CapturingTraceListener(this);
System.Diagnostics.Trace.Listeners.Add(listener);
}
public CaptureOutputLoggerFactoryAdapter(NameValueCollection properties)
public void Dispose()
{
System.Diagnostics.Trace.Listeners.Remove(listener);
}
private IList logMessages = new ArrayList();
public CaptureOutputLogger AdviceLogger
public IList LogMessages
{
get { return adviceLogger; }
get { return logMessages; }
set { logMessages = value; }
}
#region ILoggerFactoryAdapter Members
@@ -33,13 +61,13 @@ namespace Spring.Aspects.Exceptions
public ILog GetLogger(string name)
{
CaptureOutputLogger logger = new CaptureOutputLogger();
if (name.Equals("adviceHandler") || name.IndexOf("LogExceptionHandler") >= 0)
{
adviceLogger = logger;
CaptureOutputLogger logger = new CaptureOutputLogger();
return logger;
}
return logger;
return new NoOpLogger();
}
#endregion

View File

@@ -47,20 +47,23 @@ namespace Spring.Aspects.Exceptions
private CaptureOutputLoggerFactoryAdapter loggerFactoryAdapter;
private ILoggerFactoryAdapter originalAdapter;
private static bool spelActionExecuted = false;
[SetUp]
public void Setup()
{
originalAdapter = LogManager.Adapter;
loggerFactoryAdapter = new CaptureOutputLoggerFactoryAdapter();
LogManager.Adapter = loggerFactoryAdapter;
exceptionHandlerAdvice = new ExceptionHandlerAdvice();
exceptionHandlerAdvice = new ExceptionHandlerAdvice();
}
[TearDown]
public void TearDown()
{
loggerFactoryAdapter.AdviceLogger.LogMessages.Clear();
// loggerFactoryAdapter.LogMessages.Clear();
//reset so other tests can produce some output if needed.
loggerFactoryAdapter.Dispose();
LogManager.Adapter = originalAdapter;
}
@@ -89,33 +92,30 @@ namespace Spring.Aspects.Exceptions
[Test]
public void LoggingTest()
{
CaptureOutputLoggerFactoryAdapter loggerFactoryAdapter = new CaptureOutputLoggerFactoryAdapter();
LogManager.Adapter = loggerFactoryAdapter;
LogExceptionHandler logHandler = new LogExceptionHandler();
logHandler.LogName = "adviceHandler";
string testText = @"'Hello World, exception message = ' + #e.Message + ', target method = ' + #method.Name";
string testText =
@"'Hello World, exception message = ' + #e.Message + ', target method = ' + #method.Name";
logHandler.SourceExceptionNames.Add("ArithmeticException");
logHandler.ActionExpressionText = testText;
exceptionHandlerAdvice.ExceptionHandlers.Add(logHandler);
exceptionHandlerAdvice.AfterPropertiesSet();
ProxyFactory pf = new ProxyFactory(new TestObject());
pf.AddAdvice(exceptionHandlerAdvice);
ITestObject to = (ITestObject) pf.GetProxy();
ITestObject to = (ITestObject)pf.GetProxy();
try
{
to.Exceptional(new ArithmeticException());
Assert.Fail("Should have thrown exception when only logging");
} catch (ArithmeticException)
}
catch (ArithmeticException)
{
bool found = false;
foreach (string message in loggerFactoryAdapter.AdviceLogger.LogMessages)
foreach (string message in loggerFactoryAdapter.LogMessages)
{
if (message.IndexOf("Hello World") >= 0)
{
@@ -124,7 +124,6 @@ namespace Spring.Aspects.Exceptions
}
Assert.IsTrue(found, "did not find logging output");
}
}
[Test]
@@ -165,7 +164,7 @@ namespace Spring.Aspects.Exceptions
[Test]
public void LoggingTestWithConstraintExpressionWithKeyedExceptionHandler()
{
LogExceptionHandler exHandler = new LogExceptionHandler();
LogExceptionHandler exHandler = new LogExceptionHandler();
ExecuteLoggingHandlerWithKeyedLogHandler(exHandler,
@"on exception (#e is T(System.ArithmeticException)) log 'Request Timeout occured'", "Request Timeout");
}
@@ -184,7 +183,7 @@ namespace Spring.Aspects.Exceptions
{
string logHandlerText = "on exception (#e is System.FooBar) log 'My Message, Method Name ' + #method.Name";
ExecuteLoggingHandler(logHandlerText, "[WARN] Was not able to evaluate constraint expression [#e is System.FooBar]");
ExecuteLoggingHandler(logHandlerText, "[WARN] Was not able to evaluate constraint expression [#e is System.FooBar]");
}
@@ -381,10 +380,11 @@ namespace Spring.Aspects.Exceptions
ITestObject to = CreateTestObjectProxy(returnHandlerText);
try
{
to.Exceptional(new ArithmeticException("Bad Math"));
} catch (Exception e)
to.Exceptional(new ArithmeticException("Bad Math"));
}
catch (Exception e)
{
Assert.Fail("Should not have thrown exception" + e);
Assert.Fail("Should not have thrown exception" + e);
}
}
@@ -487,7 +487,7 @@ namespace Spring.Aspects.Exceptions
private void AssertSearchString(string searchString)
{
bool found = false;
foreach (string message in loggerFactoryAdapter.AdviceLogger.LogMessages)
foreach (string message in loggerFactoryAdapter.LogMessages)
{
if (message.IndexOf(searchString) >= 0)
{
@@ -495,7 +495,7 @@ namespace Spring.Aspects.Exceptions
}
}
Assert.IsTrue(found, "did not find logging output [" + searchString + "] Logging values = "
+ StringUtils.CollectionToCommaDelimitedString(loggerFactoryAdapter.AdviceLogger.LogMessages));
+ StringUtils.CollectionToCommaDelimitedString(loggerFactoryAdapter.LogMessages));
}
}
}

View File

@@ -2,9 +2,9 @@
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProductVersion>8.0.50727</ProductVersion>
<ProductVersion>9.0.30729</ProductVersion>
<SchemaVersion>2.0</SchemaVersion>
<ProjectGuid>{94E4E1B4-D424-4EB9-BF34-2EE8CC3D7048}</ProjectGuid>
<ProjectGuid>{EACD4B0B-06F9-4A0C-B8E8-EBE6BB0A167F}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>Spring</RootNamespace>
@@ -28,9 +28,9 @@
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="Castle.DynamicProxy, Version=1.1.5.0, Culture=neutral, PublicKeyToken=407dd0808d44fbdc">
<Reference Include="Castle.DynamicProxy2, Version=1.1.5.0, Culture=neutral, PublicKeyToken=407dd0808d44fbdc">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\..\lib\NHibernate20\net\2.0\Castle.DynamicProxy.dll</HintPath>
<HintPath>..\..\..\lib\NHibernate20\net\2.0\Castle.DynamicProxy2.dll</HintPath>
</Reference>
<Reference Include="Common.Logging, Version=1.1.0.0, Culture=neutral, PublicKeyToken=af08829b84f0328e">
<SpecificVersion>False</SpecificVersion>

View File

@@ -4,7 +4,7 @@
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProductVersion>9.0.30729</ProductVersion>
<SchemaVersion>2.0</SchemaVersion>
<ProjectGuid>{94E4E1B4-D424-4EB9-BF34-2EE8CC3D7048}</ProjectGuid>
<ProjectGuid>{90FEE979-7367-4542-BCCB-BF634E04A9D3}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>Spring</RootNamespace>
@@ -28,9 +28,9 @@
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="Castle.DynamicProxy, Version=1.1.5.0, Culture=neutral, PublicKeyToken=407dd0808d44fbdc">
<Reference Include="Castle.DynamicProxy2, Version=1.1.5.0, Culture=neutral, PublicKeyToken=407dd0808d44fbdc">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\..\lib\NHibernate21\net\2.0\Castle.DynamicProxy.dll</HintPath>
<HintPath>..\..\..\lib\NHibernate21\net\2.0\Castle.DynamicProxy2.dll</HintPath>
</Reference>
<Reference Include="Common.Logging, Version=1.1.0.0, Culture=neutral, PublicKeyToken=af08829b84f0328e">
<SpecificVersion>False</SpecificVersion>
@@ -126,13 +126,9 @@
<Name>Spring.Data.Tests.2008</Name>
</ProjectReference>
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="..\Spring.Data.NHibernate21.Tests\Data\NHibernate\Config\AopConfigurationTxPointcut.xml">
<Link>Data\NHibernate\Config\AopConfigurationTxPointcut.xml</Link>
</EmbeddedResource>
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="Data\NHibernate\Config\AopConfiguration.xml" />
<EmbeddedResource Include="Data\NHibernate\Config\AopConfigurationTxPointcut.xml" />
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="Data\NHibernate\TestObject.hbm.xml" />