SPRNET-1102 - Use out-of-box logging advice

This commit is contained in:
markpollack
2009-07-31 01:27:11 +00:00
parent 055ebf3a05
commit f502d14635
8 changed files with 28 additions and 285 deletions

View File

@@ -4,7 +4,7 @@ Microsoft Visual Studio Solution File, Format Version 10.00
Project("{E24C65DC-7377-472B-9ABA-BC803B73C61A}") = "Spring.Northwind.Web", "src\Spring.Northwind.Web\", "{3E321CBC-75B0-45C4-AFEF-7CEED28368AE}"
ProjectSection(WebsiteProperties) = preProject
TargetFramework = "3.5"
ProjectReferences = "{53B04C54-63EA-45AA-BB83-8950AF3C5D68}|Spring.Aspects.dll;{7F45EEA2-50AC-44E2-85A6-2FFB02E38C44}|Spring.Northwind.Dao.dll;{6E4F55A0-C281-4706-A08B-BDEC2D2FBDA4}|Spring.Northwind.Dao.NHibernate.dll;{9E15876F-E9E0-43B7-9874-B54F163757D6}|Spring.Northwind.Service.dll;{FD89FEBE-4914-45F3-9123-B2CB954810DD}|Spring.Northwind.Web.References.dll;"
ProjectReferences = "{7F45EEA2-50AC-44E2-85A6-2FFB02E38C44}|Spring.Northwind.Dao.dll;{6E4F55A0-C281-4706-A08B-BDEC2D2FBDA4}|Spring.Northwind.Dao.NHibernate.dll;{9E15876F-E9E0-43B7-9874-B54F163757D6}|Spring.Northwind.Service.dll;{FD89FEBE-4914-45F3-9123-B2CB954810DD}|Spring.Northwind.Web.References.dll;"
Debug.AspNetCompiler.VirtualPath = "/Spring.Northwind.Web"
Debug.AspNetCompiler.PhysicalPath = "src\Spring.Northwind.Web\"
Debug.AspNetCompiler.TargetPath = "PrecompiledWeb\Spring.Northwind.Web\"
@@ -19,7 +19,7 @@ Project("{E24C65DC-7377-472B-9ABA-BC803B73C61A}") = "Spring.Northwind.Web", "src
Release.AspNetCompiler.ForceOverwrite = "true"
Release.AspNetCompiler.FixedNames = "false"
Release.AspNetCompiler.Debug = "False"
VWDPort = "17866"
VWDPort = "1135"
DefaultWebSiteLanguage = "Visual C#"
EndProjectSection
EndProject
@@ -31,8 +31,6 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Spring.Northwind.Dao.NHiber
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Spring.Northwind.IntegrationTests.2008", "test\Spring.Northwind.IntegrationTests\Spring.Northwind.IntegrationTests.2008.csproj", "{2D0C5DF7-3BDB-44FB-BC1B-58E60B170BAD}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Spring.Aspects.2008", "src\Spring.Aspects\Spring.Aspects.2008.csproj", "{53B04C54-63EA-45AA-BB83-8950AF3C5D68}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Spring.Northwind.Web.References.2008", "src\Spring.Northwind.Web.References\Spring.Northwind.Web.References.2008.csproj", "{FD89FEBE-4914-45F3-9123-B2CB954810DD}"
EndProject
Global
@@ -95,16 +93,6 @@ Global
{2D0C5DF7-3BDB-44FB-BC1B-58E60B170BAD}.Release|Any CPU.Build.0 = Release|Any CPU
{2D0C5DF7-3BDB-44FB-BC1B-58E60B170BAD}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU
{2D0C5DF7-3BDB-44FB-BC1B-58E60B170BAD}.Release|Mixed Platforms.Build.0 = Release|Any CPU
{53B04C54-63EA-45AA-BB83-8950AF3C5D68}.Debug|.NET.ActiveCfg = Debug|Any CPU
{53B04C54-63EA-45AA-BB83-8950AF3C5D68}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{53B04C54-63EA-45AA-BB83-8950AF3C5D68}.Debug|Any CPU.Build.0 = Debug|Any CPU
{53B04C54-63EA-45AA-BB83-8950AF3C5D68}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU
{53B04C54-63EA-45AA-BB83-8950AF3C5D68}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU
{53B04C54-63EA-45AA-BB83-8950AF3C5D68}.Release|.NET.ActiveCfg = Release|Any CPU
{53B04C54-63EA-45AA-BB83-8950AF3C5D68}.Release|Any CPU.ActiveCfg = Release|Any CPU
{53B04C54-63EA-45AA-BB83-8950AF3C5D68}.Release|Any CPU.Build.0 = Release|Any CPU
{53B04C54-63EA-45AA-BB83-8950AF3C5D68}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU
{53B04C54-63EA-45AA-BB83-8950AF3C5D68}.Release|Mixed Platforms.Build.0 = Release|Any CPU
{FD89FEBE-4914-45F3-9123-B2CB954810DD}.Debug|.NET.ActiveCfg = Debug|Any CPU
{FD89FEBE-4914-45F3-9123-B2CB954810DD}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{FD89FEBE-4914-45F3-9123-B2CB954810DD}.Debug|Any CPU.Build.0 = Debug|Any CPU

View File

@@ -1,103 +0,0 @@
#region License
/*
* Copyright <20> 2002-2006 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#endregion
#region Imports
using System;
using AopAlliance.Intercept;
using Common.Logging;
#endregion
namespace Spring.Aspects.Logging
{
/// <summary>
/// Basic implementation of a logging aspect using Common.Logging library.
/// </summary>
/// <author>Bruno Baia</author>
/// <version>$Id: CommonLoggingAroundAdvice.cs,v 1.2 2007/06/27 16:10:59 bbaia Exp $</version>
public class CommonLoggingAroundAdvice : IMethodInterceptor
{
#region Logging
private static readonly ILog LOG = LogManager.GetLogger(typeof(CommonLoggingAroundAdvice));
#endregion
#region Fields
private LogLevel _level = LogLevel.All;
#endregion
#region Properties
public LogLevel Level
{
get { return _level; }
set { _level = value; }
}
#endregion
#region IMethodInterceptor Members
public object Invoke(IMethodInvocation invocation)
{
Log("Intercepted call : about to invoke method '{0}'", invocation.Method.Name);
object returnValue = invocation.Proceed();
Log("Intercepted call : returned '{0}'", returnValue);
return returnValue;
}
#endregion
#region Private Methods
private void Log(string text, params object[] args)
{
switch (Level)
{
case LogLevel.All:
case LogLevel.Debug:
if (LOG.IsDebugEnabled) LOG.Debug(String.Format(text, args));
break;
case LogLevel.Error:
if (LOG.IsErrorEnabled) LOG.Error(String.Format(text, args));
break;
case LogLevel.Fatal:
if (LOG.IsFatalEnabled) LOG.Fatal(String.Format(text, args));
break;
case LogLevel.Info:
if (LOG.IsInfoEnabled) LOG.Info(String.Format(text, args));
break;
case LogLevel.Warn:
if (LOG.IsWarnEnabled) LOG.Warn(String.Format(text, args));
break;
case LogLevel.Off:
default:
break;
}
}
#endregion
}
}

View File

@@ -1,35 +0,0 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("Spring.Aspects")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("Spring.Aspects")]
[assembly: AssemblyCopyright("Copyright © 2006")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
// Setting ComVisible to false makes the types in this assembly not visible
// to COM components. If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(false)]
// The following GUID is for the ID of the typelib if this project is exposed to COM
[assembly: Guid("a308abe4-e623-4315-aa51-13b52a9324d8")]
// Version information for an assembly consists of the following four values:
//
// Major Version
// Minor Version
// Build Number
// Revision
//
// You can specify all the values or you can default the Revision and Build Numbers
// by using the '*' as shown below:
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]

View File

@@ -1,60 +0,0 @@
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" ToolsVersion="3.5">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProductVersion>8.0.50727</ProductVersion>
<SchemaVersion>2.0</SchemaVersion>
<ProjectGuid>{53B04C54-63EA-45AA-BB83-8950AF3C5D68}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>Spring</RootNamespace>
<AssemblyName>Spring.Aspects</AssemblyName>
<FileUpgradeFlags>
</FileUpgradeFlags>
<OldToolsVersion>2.0</OldToolsVersion>
<UpgradeBackupLocation>
</UpgradeBackupLocation>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="Common.Logging, Version=1.0.2.0, Culture=neutral, PublicKeyToken=af08829b84f0328e">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\..\..\..\lib\Net\2.0\Common.Logging.dll</HintPath>
</Reference>
<Reference Include="Spring.Aop, Version=1.1.0.2, Culture=neutral, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\..\..\..\bin\net\2.0\debug\Spring.Aop.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Data" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="Aspects\Logging\CommonLoggingAroundAdvice.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
</Target>
<Target Name="AfterBuild">
</Target>
-->
</Project>

View File

@@ -1,55 +0,0 @@
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProductVersion>8.0.50727</ProductVersion>
<SchemaVersion>2.0</SchemaVersion>
<ProjectGuid>{53B04C54-63EA-45AA-BB83-8950AF3C5D68}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>Spring</RootNamespace>
<AssemblyName>Spring.Aspects</AssemblyName>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="Common.Logging, Version=1.0.2.0, Culture=neutral, PublicKeyToken=af08829b84f0328e">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\..\..\..\lib\Net\2.0\Common.Logging.dll</HintPath>
</Reference>
<Reference Include="Spring.Aop, Version=1.1.0.2, Culture=neutral, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\..\..\..\bin\net\2.0\debug\Spring.Aop.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Data" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="Aspects\Logging\CommonLoggingAroundAdvice.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
</Target>
<Target Name="AfterBuild">
</Target>
-->
</Project>

View File

@@ -33,17 +33,6 @@ namespace Spring.Northwind.Dao.NHibernate
[Repository]
public class HibernateCustomerDao : HibernateDao, ICustomerDao
{
[Transaction(ReadOnly = true)]
public Customer Get(string customerId)
{
return Session.Get<Customer>(customerId);
}
[Transaction(ReadOnly = true)]
public IList<Customer> GetAll()
{
return GetAll<Customer>();
}
// Note that the transaction demaraction is here only for the case when
// the DAO object is being used directly, i.e. not as part of a service layer
@@ -57,6 +46,19 @@ namespace Spring.Northwind.Dao.NHibernate
// propagation setting set to REQUIRED, then any DAO operations will use the
// same settings as started from the transactional layer.
[Transaction(ReadOnly = true)]
public Customer Get(string customerId)
{
return Session.Get<Customer>(customerId);
}
[Transaction(ReadOnly = true)]
public IList<Customer> GetAll()
{
return GetAll<Customer>();
}
[Transaction(ReadOnly = false)]
public string Save(Customer customer)
{

View File

@@ -2,8 +2,18 @@
<objects xmlns="http://www.springframework.net">
<object id="CommonLoggingAroundAdvice" type="Spring.Aspects.Logging.CommonLoggingAroundAdvice, Spring.Aspects">
<property name="Level" value="Info" />
<object name="CommonLoggingAroundAdvice" type="Spring.Aspects.Logging.SimpleLoggingAdvice, Spring.Aop">
<property name="LogUniqueIdentifier" value="true"/>
<property name="LogExecutionTime" value="true"/>
<property name="LogMethodArguments" value="true"/>
<property name="LogReturnValue" value="true"/>
<property name="Separator" value=";"/>
<property name="LogLevel" value="Info"/>
<property name="HideProxyTypeNames" value="true"/>
<property name="UseDynamicLogger" value="true"/>
</object>
</objects>

View File

@@ -2,7 +2,7 @@
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProductVersion>8.0.50727</ProductVersion>
<ProductVersion>9.0.21022</ProductVersion>
<SchemaVersion>2.0</SchemaVersion>
<ProjectGuid>{2D0C5DF7-3BDB-44FB-BC1B-58E60B170BAD}</ProjectGuid>
<OutputType>Library</OutputType>
@@ -91,10 +91,6 @@
<None Include="App.config" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\src\Spring.Aspects\Spring.Aspects.2008.csproj">
<Project>{53B04C54-63EA-45AA-BB83-8950AF3C5D68}</Project>
<Name>Spring.Aspects</Name>
</ProjectReference>
<ProjectReference Include="..\..\src\Spring.Northwind.Dao.NHibernate\Spring.Northwind.Dao.NHibernate.2008.csproj">
<Project>{6E4F55A0-C281-4706-A08B-BDEC2D2FBDA4}</Project>
<Name>Spring.Northwind.Dao.NHibernate</Name>