Logging for the datalayer now properly uses the LogHelper in Umbraco.Core
This commit is contained in:
@@ -1,7 +1,5 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading;
|
||||
using System.Web;
|
||||
using log4net;
|
||||
|
||||
@@ -25,6 +25,7 @@ using System.Runtime.InteropServices;
|
||||
[assembly: InternalsVisibleTo("businesslogic")]
|
||||
[assembly: InternalsVisibleTo("cms")]
|
||||
[assembly: InternalsVisibleTo("umbraco.editorControls")]
|
||||
[assembly: InternalsVisibleTo("umbraco.datalayer")]
|
||||
[assembly: InternalsVisibleTo("umbraco.MacroEngines")]
|
||||
|
||||
[assembly: InternalsVisibleTo("umbraco.editorControls")]
|
||||
|
||||
@@ -35,12 +35,12 @@
|
||||
<BaseRestExtensions configSource="config\BaseRestExtensions.config" />
|
||||
|
||||
<appSettings>
|
||||
<add key="umbracoDbDSN" value="server=.\sqlexpress;database=v4;user id=sa;password=test;Application Name=Umbraco41"/>
|
||||
<add key="umbracoConfigurationStatus" value="4.10.0"/>
|
||||
<add key="umbracoDbDSN" value="" />
|
||||
<add key="umbracoConfigurationStatus" value="" />
|
||||
<add key="umbracoReservedUrls" value="~/config/splashes/booting.aspx,~/install/default.aspx,~/config/splashes/noNodes.aspx,~/VSEnterpriseHelper.axd" />
|
||||
<add key="umbracoReservedPaths" value="~/umbraco,~/install/" />
|
||||
<add key="umbracoContentXML" value="~/App_Data/umbraco.config"/>
|
||||
<add key="umbracoStorageDirectory" value="~/App_Data"/>
|
||||
<add key="umbracoContentXML" value="~/App_Data/umbraco.config" />
|
||||
<add key="umbracoStorageDirectory" value="~/App_Data" />
|
||||
<add key="umbracoPath" value="~/umbraco" />
|
||||
<add key="umbracoEnableStat" value="false" />
|
||||
<add key="umbracoHideTopLevelNodeFromPath" value="true" />
|
||||
|
||||
@@ -2061,7 +2061,9 @@
|
||||
<SubType>ASPXCodeBehind</SubType>
|
||||
</Content>
|
||||
<Content Include="umbraco.presentation\umbraco\settings\stylesheet\property\EditStyleSheetProperty.aspx" />
|
||||
<Content Include="umbraco.presentation\umbraco\dialogs\sort.aspx" />
|
||||
<Content Include="umbraco.presentation\umbraco\dialogs\sort.aspx">
|
||||
<SubType>ASPXCodeBehind</SubType>
|
||||
</Content>
|
||||
<Content Include="umbraco.presentation\umbraco\test.aspx" />
|
||||
<Content Include="umbraco.presentation\umbraco\tree.aspx">
|
||||
<SubType>ASPXCodeBehind</SubType>
|
||||
|
||||
@@ -1,236 +0,0 @@
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Threading;
|
||||
using System.Web;
|
||||
using log4net;
|
||||
|
||||
namespace umbraco.DataLayer
|
||||
{
|
||||
// TODO: Make this not be a copy of the loghelper in Umbraco.Core
|
||||
// Currently this is JUST here so we can do some logging of the
|
||||
// installer and to find calls to legacy tables/columns so they
|
||||
// can be removed over time. Do not rely on this thing, it will move
|
||||
|
||||
///<summary>
|
||||
/// Used for logging
|
||||
///</summary>
|
||||
internal static class TemporaryLogHelper
|
||||
{
|
||||
///<summary>
|
||||
/// Returns a logger for the type specified
|
||||
///</summary>
|
||||
///<typeparam name="T"></typeparam>
|
||||
///<returns></returns>
|
||||
public static ILog LoggerFor<T>()
|
||||
{
|
||||
return LogManager.GetLogger(typeof(T));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns a logger for the object's type
|
||||
/// </summary>
|
||||
/// <param name="getTypeFromInstance"></param>
|
||||
/// <returns></returns>
|
||||
public static ILog LoggerFor(object getTypeFromInstance)
|
||||
{
|
||||
if (getTypeFromInstance == null) throw new ArgumentNullException("getTypeFromInstance");
|
||||
|
||||
return LogManager.GetLogger(getTypeFromInstance.GetType());
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Useful if the logger itself is running on another thread
|
||||
/// </summary>
|
||||
/// <param name="generateMessageFormat"></param>
|
||||
/// <returns></returns>
|
||||
private static string PrefixThreadId(string generateMessageFormat)
|
||||
{
|
||||
return "[Thread " + Thread.CurrentThread.ManagedThreadId + "] " + generateMessageFormat;
|
||||
}
|
||||
|
||||
#region Error
|
||||
/// <summary>
|
||||
/// Adds an error log
|
||||
/// </summary>
|
||||
/// <typeparam name="T"></typeparam>
|
||||
/// <param name="message"></param>
|
||||
/// <param name="exception"></param>
|
||||
public static void Error<T>(string message, Exception exception)
|
||||
{
|
||||
var logger = LoggerFor<T>();
|
||||
if (logger != null)
|
||||
logger.Error(PrefixThreadId(message), exception);
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region Warn
|
||||
|
||||
public static void Warn(Type callingType, string message, params object[] format)
|
||||
{
|
||||
var logger = LogManager.GetLogger(callingType);
|
||||
if (logger != null)
|
||||
logger.WarnFormat(PrefixThreadId(message), format);
|
||||
}
|
||||
|
||||
public static void Warn(Type callingType, TraceContext trace, string message, params object[] format)
|
||||
{
|
||||
if (trace != null)
|
||||
{
|
||||
trace.Warn(string.Format(message, format));
|
||||
}
|
||||
|
||||
var logger = LogManager.GetLogger(callingType);
|
||||
if (logger != null)
|
||||
logger.WarnFormat(PrefixThreadId(message), format);
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Adds a warn log
|
||||
/// </summary>
|
||||
/// <typeparam name="T"></typeparam>
|
||||
/// <param name="message"></param>
|
||||
/// <param name="items"></param>
|
||||
public static void Warn<T>(string message, params object[] items)
|
||||
{
|
||||
var logger = LoggerFor<T>();
|
||||
if (logger != null)
|
||||
logger.WarnFormat(PrefixThreadId(message), items);
|
||||
}
|
||||
|
||||
public static void Warn<T>(string message, TraceContext trace, params object[] items)
|
||||
{
|
||||
if (trace != null)
|
||||
{
|
||||
trace.Warn(string.Format(message, items));
|
||||
}
|
||||
|
||||
var logger = LoggerFor<T>();
|
||||
if (logger != null)
|
||||
logger.WarnFormat(PrefixThreadId(message), items);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Info
|
||||
/// <summary>
|
||||
/// Traces a message, only generating the message if tracing is actually enabled. Use this method to avoid calling any long-running methods such as "ToDebugString" if logging is disabled.
|
||||
/// </summary>
|
||||
/// <typeparam name="T"></typeparam>
|
||||
/// <param name="generateMessage">The delegate to generate a message.</param>
|
||||
/// <remarks></remarks>
|
||||
public static void Info<T>(Func<string> generateMessage)
|
||||
{
|
||||
Info(typeof(T), generateMessage);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Traces if tracing is enabled.
|
||||
/// </summary>
|
||||
/// <param name="callingType"></param>
|
||||
/// <param name="generateMessage"></param>
|
||||
public static void Info(Type callingType, Func<string> generateMessage)
|
||||
{
|
||||
var logger = LogManager.GetLogger(callingType);
|
||||
if (logger == null || !logger.IsInfoEnabled) return;
|
||||
logger.Info(PrefixThreadId(generateMessage.Invoke()));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Traces if tracing is enabled.
|
||||
/// </summary>
|
||||
/// <param name="type">The type for the logging namespace.</param>
|
||||
/// <param name="generateMessageFormat">The message format.</param>
|
||||
/// <param name="formatItems">The format items.</param>
|
||||
public static void Info(Type type, string generateMessageFormat, params Func<object>[] formatItems)
|
||||
{
|
||||
var logger = LogManager.GetLogger(type);
|
||||
if (logger == null || !logger.IsInfoEnabled) return;
|
||||
var executedParams = formatItems.Select(x => x.Invoke()).ToArray();
|
||||
logger.InfoFormat(PrefixThreadId(generateMessageFormat), executedParams);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Traces a message, only generating the message if tracing is actually enabled. Use this method to avoid calling any long-running methods such as "ToDebugString" if logging is disabled.
|
||||
/// </summary>
|
||||
/// <typeparam name="T"></typeparam>
|
||||
/// <param name="generateMessageFormat">The generate message format.</param>
|
||||
/// <param name="formatItems">The format items.</param>
|
||||
/// <remarks></remarks>
|
||||
public static void Info<T>(string generateMessageFormat, params Func<object>[] formatItems)
|
||||
{
|
||||
Info(typeof(T), generateMessageFormat, formatItems);
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region Debug
|
||||
/// <summary>
|
||||
/// Debugs a message, only generating the message if tracing is actually enabled. Use this method to avoid calling any long-running methods such as "ToDebugString" if logging is disabled.
|
||||
/// </summary>
|
||||
/// <typeparam name="T"></typeparam>
|
||||
/// <param name="generateMessage">The delegate to generate a message.</param>
|
||||
/// <remarks></remarks>
|
||||
public static void Debug<T>(Func<string> generateMessage)
|
||||
{
|
||||
Debug(typeof(T), generateMessage);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Debugs if tracing is enabled.
|
||||
/// </summary>
|
||||
/// <param name="callingType"></param>
|
||||
/// <param name="generateMessage"></param>
|
||||
public static void Debug(Type callingType, Func<string> generateMessage)
|
||||
{
|
||||
var logger = LogManager.GetLogger(callingType);
|
||||
if (logger == null || !logger.IsDebugEnabled) return;
|
||||
logger.Debug(PrefixThreadId(generateMessage.Invoke()));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Debugs if tracing is enabled.
|
||||
/// </summary>
|
||||
/// <param name="type">The type for the logging namespace.</param>
|
||||
/// <param name="generateMessageFormat">The message format.</param>
|
||||
/// <param name="formatItems">The format items.</param>
|
||||
public static void Debug(Type type, string generateMessageFormat, params Func<object>[] formatItems)
|
||||
{
|
||||
var logger = LogManager.GetLogger(type);
|
||||
if (logger == null || !logger.IsDebugEnabled) return;
|
||||
var executedParams = formatItems.Select(x => x.Invoke()).ToArray();
|
||||
logger.DebugFormat(PrefixThreadId(generateMessageFormat), executedParams);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Debugs a message, only generating the message if debug is actually enabled. Use this method to avoid calling any long-running methods such as "ToDebugString" if logging is disabled.
|
||||
/// </summary>
|
||||
/// <typeparam name="T"></typeparam>
|
||||
/// <param name="generateMessageFormat">The generate message format.</param>
|
||||
/// <param name="formatItems">The format items.</param>
|
||||
/// <remarks></remarks>
|
||||
public static void Debug<T>(string generateMessageFormat, params Func<object>[] formatItems)
|
||||
{
|
||||
Debug(typeof(T), generateMessageFormat, formatItems);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Debugs a message and also writes to the TraceContext specified, useful for when you would like the debug
|
||||
/// output also displayed in the Http trace output.
|
||||
/// </summary>
|
||||
/// <typeparam name="T"></typeparam>
|
||||
/// <param name="generateMessageFormat"></param>
|
||||
/// <param name="trace"></param>
|
||||
/// <param name="formatItems"></param>
|
||||
public static void Debug<T>(string generateMessageFormat, TraceContext trace, params Func<object>[] formatItems)
|
||||
{
|
||||
if (trace != null)
|
||||
{
|
||||
trace.Write(string.Format(generateMessageFormat, formatItems.Select(x => x())));
|
||||
}
|
||||
Debug(typeof(T), generateMessageFormat, formatItems);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
}
|
||||
}
|
||||
@@ -12,6 +12,7 @@ using System.Diagnostics;
|
||||
using System.IO;
|
||||
using System.Xml;
|
||||
using umbraco.DataLayer.Utility;
|
||||
using Umbraco.Core.Logging;
|
||||
|
||||
namespace umbraco.DataLayer
|
||||
{
|
||||
@@ -123,18 +124,13 @@ namespace umbraco.DataLayer
|
||||
throw new ArgumentNullException("parameters");
|
||||
|
||||
// Add raw types of parameters to an array
|
||||
P[] newParams = new P[parameters.Length];
|
||||
for (int index = 0; index < parameters.Length; index++)
|
||||
var newParams = new P[parameters.Length];
|
||||
for (var index = 0; index < parameters.Length; index++)
|
||||
{
|
||||
// Get raw type out of container
|
||||
IParameterContainer<P> parameter = parameters[index] as IParameterContainer<P>;
|
||||
var parameter = parameters[index] as IParameterContainer<P>;
|
||||
if (parameter == null)
|
||||
throw new ArgumentException(
|
||||
String.Format("Element {0} of parameters has the wrong type. Expected: IParameterContainer<{1}>. Received: {2}.",
|
||||
index,
|
||||
typeof(P).Name,
|
||||
(parameter==null ? "null" : parameter.GetType().Name)),
|
||||
"parameters");
|
||||
throw new ArgumentException(String.Format("Element {0} of parameters has the wrong type. Expected: IParameterContainer<{1}>. Received: null.", index, typeof(P).Name), "parameters");
|
||||
newParams[index] = parameter.RawParameter;
|
||||
}
|
||||
return newParams;
|
||||
@@ -198,7 +194,7 @@ namespace umbraco.DataLayer
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
TemporaryLogHelper.Error<SqlHelper<P>>(string.Format("Error executing query {0}", commandText), e);
|
||||
LogHelper.Error<SqlHelper<P>>(string.Format("Error executing query {0}", commandText), e);
|
||||
throw new SqlHelperException("ExecuteScalar", commandText, parameters, e);
|
||||
}
|
||||
}
|
||||
@@ -222,7 +218,7 @@ namespace umbraco.DataLayer
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
TemporaryLogHelper.Error<SqlHelper<P>>(string.Format("Error executing query {0}", commandText), e);
|
||||
LogHelper.Error<SqlHelper<P>>(string.Format("Error executing query {0}", commandText), e);
|
||||
throw new SqlHelperException("ExecuteNonQuery", commandText, parameters, e);
|
||||
}
|
||||
}
|
||||
@@ -242,11 +238,12 @@ namespace umbraco.DataLayer
|
||||
P[] parametersConverted = ConvertParameters(parameters);
|
||||
try
|
||||
{
|
||||
LogHelper.Info<SqlHelper<P>>(string.Format("Executing query {0}", commandText));
|
||||
return ExecuteReader(commandConverted.TrimToOneLine(), parametersConverted);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
TemporaryLogHelper.Error<SqlHelper<P>>(string.Format("Error executing query {0}", commandText), e);
|
||||
LogHelper.Error<SqlHelper<P>>(string.Format("Error executing query {0}", commandText), e);
|
||||
throw new SqlHelperException("ExecuteReader", commandText, parameters, e);
|
||||
}
|
||||
}
|
||||
@@ -270,7 +267,7 @@ namespace umbraco.DataLayer
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
TemporaryLogHelper.Error<SqlHelper<P>>(string.Format("Error executing query {0}", commandText), e);
|
||||
LogHelper.Error<SqlHelper<P>>(string.Format("Error executing query {0}", commandText), e);
|
||||
throw new SqlHelperException("ExecuteXmlReader", commandText, parameters, e);
|
||||
}
|
||||
}
|
||||
@@ -317,7 +314,7 @@ namespace umbraco.DataLayer
|
||||
/// </returns>
|
||||
protected virtual XmlReader ExecuteXmlReader(string commandText, params P[] parameters)
|
||||
{
|
||||
string xmlString = (string)ExecuteScalar(commandText, parameters);
|
||||
var xmlString = (string)ExecuteScalar(commandText, parameters);
|
||||
if (xmlString == null)
|
||||
throw new ArgumentException("The query didn't return a value.");
|
||||
|
||||
|
||||
@@ -64,9 +64,6 @@
|
||||
<CodeAnalysisRuleSet>AllRules.ruleset</CodeAnalysisRuleSet>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="log4net">
|
||||
<HintPath>..\packages\log4net.2.0.0\lib\net40-full\log4net.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="Microsoft.ApplicationBlocks.Data, Version=1.0.1559.20655, Culture=neutral">
|
||||
<SpecificVersion>False</SpecificVersion>
|
||||
<HintPath>..\..\lib\Microsoft.ApplicationBlocks.Data.dll</HintPath>
|
||||
@@ -97,7 +94,6 @@
|
||||
<Compile Include="IRecordsReader.cs" />
|
||||
<Compile Include="ISqlHelper.cs" />
|
||||
<Compile Include="IParameterContainer.cs" />
|
||||
<Compile Include="LogHelper.cs" />
|
||||
<Compile Include="SqlHelperException.cs" />
|
||||
<Compile Include="SqlHelpers\MySql\MySqlInstaller.cs" />
|
||||
<Compile Include="SqlHelpers\MySql\MySqlParser.cs" />
|
||||
@@ -198,6 +194,12 @@
|
||||
<ItemGroup>
|
||||
<Content Include="SqlHelpers\SqlServer\Sql\Version4_8_Upgrade.sql" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\Umbraco.Core\Umbraco.Core.csproj">
|
||||
<Project>{31785bc3-256c-4613-b2f5-a1b0bdded8c1}</Project>
|
||||
<Name>Umbraco.Core</Name>
|
||||
</ProjectReference>
|
||||
</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.
|
||||
|
||||
Reference in New Issue
Block a user