Inline logger helpers for idiomatic usage (#270)

This commit is contained in:
Marko Lahma
2025-03-28 20:01:17 +02:00
committed by GitHub
parent fda46d95b1
commit 67cd5b83a9
212 changed files with 1142 additions and 1111 deletions

View File

@@ -23,8 +23,7 @@
using System;
using System.Collections.Generic;
using System.Reflection;
using Microsoft.Extensions.Logging;
using NUnit.Framework;
using Spring.Aop.Support;
@@ -90,20 +89,20 @@ namespace Spring.Aop.Framework.AutoProxy
public TestDefaultAdvisorAutoProxyCreator()
{
_logger = LogManager.GetLogger(this.GetType().Name + "#" + GetHashCode());
_logger.Trace("Created instance");
_logger.LogTrace("Created instance");
}
protected override IList<object> GetAdvicesAndAdvisorsForObject(Type targetType, string targetName, ITargetSource customTargetSource)
{
_logger.Trace("GetAdvicesAndAdvisorsForObject begin");
_logger.LogTrace("GetAdvicesAndAdvisorsForObject begin");
IList<object> advices = base.GetAdvicesAndAdvisorsForObject(targetType, targetName, customTargetSource);
_logger.Trace("GetAdvicesAndAdvisorsForObject end");
_logger.LogTrace("GetAdvicesAndAdvisorsForObject end");
return advices;
}
public override void AfterPropertiesSet()
{
_logger.Trace("AfterPropertiesSet");
_logger.LogTrace("AfterPropertiesSet");
base.AfterPropertiesSet();
}
}
@@ -125,7 +124,7 @@ namespace Spring.Aop.Framework.AutoProxy
public CountingAfterReturningAdvisor()
{
LogManager.GetLogger(this.GetType()).Trace("Created instance #" + this.GetHashCode());
LogManager.GetLogger(this.GetType()).LogTrace("Created instance #" + this.GetHashCode());
base.Advice = new CountingAfterReturningAdvice();
}
@@ -139,7 +138,7 @@ namespace Spring.Aop.Framework.AutoProxy
{
public SomeOtherObject()
{
LogManager.GetLogger(this.GetType()).Trace("Created instance #" + this.GetHashCode());
LogManager.GetLogger(this.GetType()).LogTrace("Created instance #" + this.GetHashCode());
}
public object Clone()
@@ -152,7 +151,7 @@ namespace Spring.Aop.Framework.AutoProxy
{
public IndependentObject()
{
LogManager.GetLogger(this.GetType()).Trace("Created instance #" + this.GetHashCode());
LogManager.GetLogger(this.GetType()).LogTrace("Created instance #" + this.GetHashCode());
}
public object Clone()
@@ -173,7 +172,7 @@ namespace Spring.Aop.Framework.AutoProxy
public TestObjectFactoryObject()
{
_logger = LogManager.GetLogger(this.GetType().Name + "#" + this.GetHashCode());
_logger.Trace("Created instance");
_logger.LogTrace("Created instance");
}
public SomeOtherObject SomeOtherObject
@@ -188,10 +187,10 @@ namespace Spring.Aop.Framework.AutoProxy
// return product only, if factory has been fully initialized!
if (!initialized)
{
_logger.Trace("GetObject(): not initialized, returning null");
_logger.LogTrace("GetObject(): not initialized, returning null");
return null;
}
_logger.Trace("GetObject(): initialized, returning testObject");
_logger.LogTrace("GetObject(): initialized, returning testObject");
return testObject;
}
@@ -202,10 +201,10 @@ namespace Spring.Aop.Framework.AutoProxy
// return type only if we are ready to deliver our product!
if (!initialized)
{
_logger.Trace("get_ObjectType(): not initialized, returning null");
_logger.LogTrace("get_ObjectType(): not initialized, returning null");
return null;
}
_logger.Trace("get_ObjectType(): initialized, returning typeof(ITestObject)");
_logger.LogTrace("get_ObjectType(): initialized, returning typeof(ITestObject)");
return typeof(ITestObject);
}
}
@@ -217,7 +216,7 @@ namespace Spring.Aop.Framework.AutoProxy
public void AfterPropertiesSet()
{
_logger.Trace("AfterPropertiesSet");
_logger.LogTrace("AfterPropertiesSet");
Assert.IsNotNull(someOtherObject);
testObject = new TestObject();
initialized = true;

View File

@@ -16,6 +16,7 @@
using System.Reflection;
using System.Collections;
using Microsoft.Extensions.Logging;
using NUnit.Framework;
using Spring.Objects;
using Spring.Objects.Factory;
@@ -112,9 +113,9 @@ namespace Spring.Aop.Target
public virtual void Run ()
{
log.Debug ("getting object");
log.LogDebug("getting object");
this.mine = (ISideEffectObject) factory.ObjectFactory.GetObject ("apartment");
log.Debug (String.Format ("got object; hash code: {0}", this.mine.GetHashCode ()));
log.LogDebug(String.Format ("got object; hash code: {0}", this.mine.GetHashCode ()));
Assert.AreEqual (ThreadLocalTargetSourceTests.INITIAL_COUNT, mine.Count);
mine.doWork ();
Assert.AreEqual (ThreadLocalTargetSourceTests.INITIAL_COUNT + 1, mine.Count);
@@ -125,7 +126,7 @@ namespace Spring.Aop.Target
public virtual void NewThreadHasOwnInstance ()
{
ISideEffectObject apartment = (ISideEffectObject) ObjectFactory.GetObject ("apartment");
log.Debug (String.Format ("got object; hash code: {0}", apartment.GetHashCode ()));
log.LogDebug(String.Format ("got object; hash code: {0}", apartment.GetHashCode ()));
Assert.AreEqual (INITIAL_COUNT, apartment.Count);
apartment.doWork ();
apartment.doWork ();

View File

@@ -1,4 +1,5 @@
using AopAlliance.Intercept;
using Microsoft.Extensions.Logging;
namespace Spring.Data
{
@@ -7,9 +8,9 @@ namespace Spring.Data
private static readonly ILog LOG = LogManager.GetLogger(typeof(ConsoleLoggingAroundAdvice));
public object Invoke(IMethodInvocation invocation)
{
LOG.Debug("Advice executing; calling the advised method [" + invocation.Method.Name + "]");
LOG.LogDebug("Advice executing; calling the advised method [" + invocation.Method.Name + "]");
object returnValue = invocation.Proceed();
LOG.Debug("Advice executed; advised method [" + invocation.Method.Name + "] returned " + returnValue);
LOG.LogDebug("Advice executed; advised method [" + invocation.Method.Name + "] returned " + returnValue);
return returnValue;
}
}

View File

@@ -21,6 +21,7 @@
#region Imports
using System.Data;
using Microsoft.Extensions.Logging;
using NUnit.Framework;
using Spring.Context;
using Spring.Context.Support;
@@ -74,11 +75,11 @@ namespace Spring.Data.Support
catch (BadSqlGrammarException e)
{
log.Error("caught correct exception", e);
log.LogError(e, "caught correct exception");
}
catch (Exception e)
{
log.Error("caught incorrect exception ", e);
log.LogError(e, "caught incorrect exception ");
Assert.Fail("did not throw exception of type BadSqlGrammerException");
}

View File

@@ -21,6 +21,7 @@
#region Imports
using System.Collections;
using Microsoft.Extensions.Logging;
using Spring.Objects;
using Spring.Transaction.Interceptor;
using Spring.Transaction.Support;
@@ -66,7 +67,7 @@ namespace Spring.Data
[Transaction]
public void SaveTwoTestObjects(TestObject to1, TestObject to2)
{
LOG.Debug("TransactionActive = " + TransactionSynchronizationManager.ActualTransactionActive);
LOG.LogDebug("TransactionActive = " + TransactionSynchronizationManager.ActualTransactionActive);
//Console.WriteLine("TransactionSynchronizationManager.CurrentTransactionIsolationLevel = " +
// TransactionSynchronizationManager.CurrentTransactionIsolationLevel);
//Console.WriteLine("System.Transactions.Transaction.Current.IsolationLevel = " + System.Transactions.Transaction.Current.IsolationLevel);

View File

@@ -1,4 +1,5 @@
using System.Data;
using Microsoft.Extensions.Logging;
using Spring.Data.Core;
namespace Spring.Data.NHibernate
@@ -9,11 +10,11 @@ namespace Spring.Data.NHibernate
LogManager.GetLogger(typeof(AuditDao));
public void AuditOperation(string operationIdenfitier)
{
logger.Debug("Executing AUDIT operation.");
logger.LogDebug("Executing AUDIT operation.");
AdoTemplate.ExecuteNonQuery(CommandType.Text,
"insert into AuditTable (AuditId) values (@AuditId)",
"AuditId", DbType.String, 100, operationIdenfitier);
logger.Debug("AUDIT operation done.");
logger.LogDebug("AUDIT operation done.");
}
}
}

View File

@@ -1,5 +1,6 @@
using AopAlliance.Intercept;
using Microsoft.Extensions.Logging;
namespace Spring.Data
{
@@ -11,9 +12,9 @@ namespace Spring.Data
{
try
{
LOG.Debug("Advice executing; calling the advised method [" + invocation.Method.Name + "]");
LOG.LogDebug("Advice executing; calling the advised method [" + invocation.Method.Name + "]");
object returnValue = invocation.Proceed();
LOG.Debug("Advice executed; advised method [" + invocation.Method.Name + "] returned " + returnValue);
LOG.LogDebug("Advice executed; advised method [" + invocation.Method.Name + "] returned " + returnValue);
return returnValue;
} finally
{

View File

@@ -15,6 +15,7 @@
*/
using System.Transactions;
using Microsoft.Extensions.Logging;
using Spring.Objects;
using Spring.Transaction;
using Spring.Transaction.Interceptor;
@@ -41,7 +42,7 @@ namespace Spring.Data
[Transaction()]
public void SaveTwoTestObjects(TestObject to1, TestObject to2)
{
LOG.Debug("TransactionActive = " + TransactionSynchronizationManager.ActualTransactionActive);
LOG.LogDebug("TransactionActive = " + TransactionSynchronizationManager.ActualTransactionActive);
}
[Transaction(TransactionPropagation.Required, IsolationLevel.Unspecified, Timeout = 50,

View File

@@ -1,4 +1,6 @@
using Microsoft.Extensions.Logging;
namespace Spring.Messaging.Ems.Core
{
public class SimpleMessageListener : IMessageListener
@@ -15,14 +17,14 @@ namespace Spring.Messaging.Ems.Core
public void OnMessage(Message message)
{
messageCount++;
LOG.Debug("Message listener count = " + messageCount);
LOG.LogDebug("Message listener count = " + messageCount);
TextMessage textMessage = message as TextMessage;
if (textMessage != null)
{
LOG.Info("Message Text = " + textMessage.Text);
LOG.LogInformation("Message Text = " + textMessage.Text);
} else
{
LOG.Warn("Can not process message of type " + message.GetType());
LOG.LogWarning("Can not process message of type " + message.GetType());
}
}
}

View File

@@ -19,6 +19,7 @@
#endregion
using Apache.NMS;
using Microsoft.Extensions.Logging;
namespace Spring.Messaging.Nms.Core
{
@@ -38,15 +39,15 @@ namespace Spring.Messaging.Nms.Core
public void OnMessage(IMessage message)
{
messageCount++;
LOG.Debug("Message listener count = " + messageCount);
LOG.LogDebug("Message listener count = " + messageCount);
ITextMessage textMessage = message as ITextMessage;
if (textMessage != null)
{
LOG.Info("Message Text = " + textMessage.Text);
LOG.LogInformation("Message Text = " + textMessage.Text);
}
else
{
LOG.Warn("Can not process message of type " + message.GetType());
LOG.LogWarning("Can not process message of type " + message.GetType());
}
}

View File

@@ -1,3 +1,4 @@
using Microsoft.Extensions.Logging;
using Spring.Messaging.Nms.Core;
namespace Spring.Messaging.Nms.Integration
@@ -18,7 +19,7 @@ namespace Spring.Messaging.Nms.Integration
public void OnException(Exception e)
{
LOG.Error("Exception processing message", e);
LOG.LogError(e, "Exception processing message");
}
#endregion

View File

@@ -2,6 +2,7 @@
using Spring.Messaging.Nms.Core;
using Apache.NMS;
using Microsoft.Extensions.Logging;
namespace Spring.Messaging.Nms.Integration
{
@@ -32,7 +33,7 @@ namespace Spring.Messaging.Nms.Integration
{
lastReceivedMessage = message;
messageCount++;
LOG.Debug("Message listener count = " + messageCount);
LOG.LogDebug("Message listener count = " + messageCount);
}
#endregion

View File

@@ -1,6 +1,7 @@
using System;
using System.Messaging;
using System.Threading;
using Microsoft.Extensions.Logging;
namespace Spring.Messaging.Listener
{
@@ -52,13 +53,13 @@ namespace Spring.Messaging.Listener
Thread.Sleep(recoveryTimeSpan);
break;
default:
LOG.Error("Exception Receiving Message", e);
LOG.LogError(e, "Exception Receiving Message");
break;
}
}
else
{
LOG.Error("got exception", exception);
LOG.LogError(exception, "got exception");
}
}

View File

@@ -1,4 +1,5 @@
using System.Messaging;
using Microsoft.Extensions.Logging;
namespace Spring.Messaging.Listener
{
@@ -23,8 +24,8 @@ namespace Spring.Messaging.Listener
public void OnException(Exception exception, Message message)
{
LOG.Error("Exception Handler processing message id = [" + message.Id + "]");
LOG.Error("Exception = ", exception);
LOG.LogError("Exception Handler processing message id = [" + message.Id + "]");
LOG.LogError(exception, "Exception = ");
messageCount++;
}

View File

@@ -1,6 +1,7 @@
using System;
using Microsoft.Extensions.Logging;
namespace Spring.Messaging.Listener
{
@@ -34,14 +35,14 @@ namespace Spring.Messaging.Listener
public string HandleMessage(string msgTxt)
{
LOG.Debug("Received text = [" + msgTxt + "]");
LOG.Debug("constructor set state string = " + stateVariable);
LOG.LogDebug("Received text = [" + msgTxt + "]");
LOG.LogDebug("constructor set state string = " + stateVariable);
if (msgTxt.Contains("Goodbye"))
{
throw new ArgumentException("Don't like saying goodbye!");
}
messageCount++;
LOG.Debug("Message listener count = " + messageCount);
LOG.LogDebug("Message listener count = " + messageCount);
return msgTxt + " - processed!";
}
}

View File

@@ -1,6 +1,7 @@
using System.Messaging;
using Microsoft.Extensions.Logging;
namespace Spring.Messaging.Listener
{
@@ -31,7 +32,7 @@ namespace Spring.Messaging.Listener
{
lastReceivedMessage = message;
messageCount++;
LOG.Debug("Message listener count = " + messageCount);
LOG.LogDebug("Message listener count = " + messageCount);
}
#endregion

View File

@@ -2,6 +2,7 @@
using System;
using System.Threading;
using Microsoft.Extensions.Logging;
namespace Spring.Messaging.Listener
{
@@ -35,13 +36,13 @@ namespace Spring.Messaging.Listener
public string HandleMessage(string msgTxt)
{
LOG.Debug(String.Format("Received text = [{0}]", msgTxt));
LOG.Debug("constructor set state string = " + stateVariable);
LOG.LogDebug(String.Format("Received text = [{0}]", msgTxt));
LOG.LogDebug("constructor set state string = " + stateVariable);
Thread.Sleep(10000);
messageCount++;
LOG.Debug("Message listener count = " + messageCount);
LOG.LogDebug("Message listener count = " + messageCount);
return msgTxt + " - processed!";
}
}

View File

@@ -153,7 +153,7 @@ namespace Spring.Web.Conversation
public override Type BindToType(string assemblyName, string typeName)
{
if (LOG.IsEnabled(LogLevel.Debug))
LOG.Debug(String.Format("MyBinder.BindToType: {0}, {1}", typeName, assemblyName));
LOG.LogDebug(String.Format("MyBinder.BindToType: {0}, {1}", typeName, assemblyName));
return Type.GetType(typeName + ", " + assemblyName);
}
}
@@ -211,7 +211,7 @@ namespace Spring.Web.Conversation
public void GetObjectData(object obj, SerializationInfo info, StreamingContext context)
{
if (LOG.IsEnabled(LogLevel.Debug))
LOG.Debug(String.Format("MySerializationSurrogateWrapper.GetObjectData({0},...", obj.GetType()));
LOG.LogDebug(String.Format("MySerializationSurrogateWrapper.GetObjectData({0},...", obj.GetType()));
FieldInfo[] fields = obj.GetType().GetFields(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.FlattenHierarchy);
if (obj is ISerializable)
@@ -233,7 +233,7 @@ namespace Spring.Web.Conversation
public object SetObjectData(object obj, SerializationInfo info, StreamingContext context, ISurrogateSelector selector)
{
if (LOG.IsEnabled(LogLevel.Debug))
LOG.Debug(String.Format("MySerializationSurrogateWrapper.SetObjectData({0},...", obj.GetType()));
LOG.LogDebug(String.Format("MySerializationSurrogateWrapper.SetObjectData({0},...", obj.GetType()));
FieldInfo[] fields = obj.GetType().GetFields(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance);

View File

@@ -1,5 +1,6 @@
using System;
using System.Text;
using Microsoft.Extensions.Logging;
using Spring;
using Spring.Context;
using Spring.Web.Conversation;
@@ -21,7 +22,7 @@ public partial class CircularDependenceTest : System.Web.UI.Page, IApplicationCo
}
catch (InvalidOperationException ioe)
{
LOG.Debug("SERVER SIDE ERROR", ioe);
LOG.LogDebug(ioe, "SERVER SIDE ERROR");
if (!ioe.Message.Contains("convCircularDependenceTest_A_A_A->convCircularDependenceTest_A->convCircularDependenceTest_A_A->convCircularDependenceTest_A_A_A"))
{
sbErrors.AppendLine(String.Format("Wrong CircularDependence message= '{0}'", ioe.Message));
@@ -29,7 +30,7 @@ public partial class CircularDependenceTest : System.Web.UI.Page, IApplicationCo
}
catch (Exception ex)
{
LOG.Error("SERVER SIDE ERROR", ex);
LOG.LogError(ex, "SERVER SIDE ERROR");
sbErrors.AppendLine(String.Format("Unexpected Error: '{0}' \n {1}", ex.Message, ex.StackTrace));
}

View File

@@ -1,3 +1,4 @@
using Microsoft.Extensions.Logging;
using Spring.Web.Conversation;
using Spring.Entities;
using NHibernate;
@@ -22,7 +23,7 @@ public partial class SPCLazyLoadTest_A_Status : System.Web.UI.Page
SPCMasterEnt sPCMasterEnt = (SPCMasterEnt)this.Session["sPCMasterEnt"];
foreach (SPCDetailEnt sPCDetailEntItem in sPCMasterEnt.SPCDetailEntList)
{
LOG.Debug(String.Format("Page_Load: sPCDetailEntItem.Description={0}", sPCDetailEntItem.Description));
LOG.LogDebug(String.Format("Page_Load: sPCDetailEntItem.Description={0}", sPCDetailEntItem.Description));
}
this.Session["messageTest"] = "no lazy error";
}

View File

@@ -1,5 +1,5 @@
using System;
using Microsoft.Extensions.Logging;
using Spring.Web.Conversation;
using Spring.Entities;
using NHibernate;
@@ -98,7 +98,7 @@ public partial class SPCSwitchConversationSameRequest : System.Web.UI.Page
{
foreach (SPCDetailEnt sPCDetailEntItem in sPCMasterEnt.SPCDetailEntList)
{
LOG.Debug(String.Format("Page_Load({1}): sPCDetailEntItem.Description={0}", sPCDetailEntItem.Description, desc));
LOG.LogDebug(String.Format("Page_Load({1}): sPCDetailEntItem.Description={0}", sPCDetailEntItem.Description, desc));
}
}
}

View File

@@ -1,4 +1,5 @@
using System;
using Microsoft.Extensions.Logging;
namespace Spring.Data.Objects.Factory.Support
{
@@ -13,7 +14,7 @@ namespace Spring.Data.Objects.Factory.Support
protected void Page_Load(object sender, EventArgs e)
{
_log.Debug("loaded page!");
_log.LogDebug("loaded page!");
}
}
}