Skip to content

Commit 67cd5b8

Browse files
authored
Inline logger helpers for idiomatic usage (#270)
1 parent fda46d9 commit 67cd5b8

File tree

212 files changed

+1142
-1111
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

212 files changed

+1142
-1111
lines changed

build-support/nuke-build/Build.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ partial class Build : NukeBuild
3737
readonly bool BuildEms = false;
3838

3939
[Parameter("Version")]
40-
readonly string ProjectVersion = "3.0.2";
40+
readonly string ProjectVersion = "3.1.0";
4141

4242
[Solution] readonly Solution Solution;
4343
[GitRepository] readonly GitRepository GitRepository;

examples/Spring/Spring.Data.NHibernate.Northwind/src/Spring.Northwind.Service/Service/FedExShippingService.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ public class FedExShippingService : IShippingService
3333

3434
public void ShipOrder(Order order)
3535
{
36-
log.Info("Shipping order id = " + order.Id);
36+
log.LogInformation("Shipping order id = {OrderId} ", order.Id);
3737
}
3838
}
3939
}

examples/Spring/Spring.Data.NHibernate.Northwind/src/Spring.Northwind.Service/Service/FulfillmentService.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -90,13 +90,13 @@ public void ProcessCustomer(string customerId)
9090
{
9191
if (order.ShippedDate.HasValue)
9292
{
93-
log.Warn("Order with " + order.Id + " has already been shipped, skipping.");
93+
log.LogWarning("Order {OrderId} has already been shipped, skipping.", order.Id);
9494
continue;
9595
}
9696

9797
//Validate Order
9898
Validate(order);
99-
log.Info("Order " + order.Id + " validated, proceeding with shipping..");
99+
log.LogInformation("Order {OrderId} validated, proceeding with shipping..", order.Id);
100100

101101
//Ship with external shipping service
102102
ShippingService.ShipOrder(order);

examples/Spring/Spring.IoCQuickStart.MovieFinder/src/MovieFinder/Program.cs

+4-6
Original file line numberDiff line numberDiff line change
@@ -67,18 +67,16 @@ public static void Main()
6767

6868
MovieLister lister = (MovieLister) ctx.GetObject("MyMovieLister");
6969
Movie[] movies = lister.MoviesDirectedBy("Roberto Benigni");
70-
LOG.Debug("Searching for movie...");
70+
LOG.LogDebug("Searching for movie...");
7171
foreach (Movie movie in movies)
7272
{
73-
LOG.Debug(
74-
string.Format("Movie Title = '{0}', Director = '{1}'.",
75-
movie.Title, movie.Director));
73+
LOG.LogDebug("Movie Title = '{Title}', Director = '{Director}'.", movie.Title, movie.Director);
7674
}
77-
LOG.Debug("MovieApp Done.");
75+
LOG.LogDebug("MovieApp Done.");
7876
}
7977
catch (Exception e)
8078
{
81-
LOG.Error("Movie Finder is broken.", e);
79+
LOG.LogError("Movie Finder is broken.", e);
8280
}
8381
finally
8482
{

examples/Spring/Spring.MsmqQuickStart/src/Spring/Spring.MsmqQuickStart.Client/Handlers/StockAppHandler.cs

+3-3
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ public StockController StockController
2323

2424
public void Handle(string data)
2525
{
26-
log.Info(string.Format("Received market data. " + data));
26+
log.LogInformation("Received market data. " + data);
2727

2828
// forward to controller to update view
2929
stockController.UpdateMarketData(data);
@@ -33,13 +33,13 @@ public void Handle(string data)
3333

3434
public void Handle(TradeResponse tradeResponse)
3535
{
36-
log.Info(string.Format("Received trade resonse. Ticker = {0}, Price = {1}", tradeResponse.Ticker, tradeResponse.Price));
36+
log.LogInformation("Received trade resonse. Ticker = {TradeResponseTicker}, Price = {TradeResponsePrice}", tradeResponse.Ticker, tradeResponse.Price);
3737
stockController.UpdateTrade(tradeResponse);
3838
}
3939

4040
public void Handle(object catchAllObject)
4141
{
42-
log.Error("could not handle object of type = " + catchAllObject.GetType());
42+
log.LogError("could not handle object of type {ObjectType}", catchAllObject.GetType());
4343
}
4444
}
4545
}

examples/Spring/Spring.MsmqQuickStart/src/Spring/Spring.MsmqQuickStart.Client/Program.cs

+3-3
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ static void Main()
2222
{
2323
try
2424
{
25-
log.Info("Running....");
25+
log.LogInformation("Running....");
2626
Application.EnableVisualStyles();
2727
Application.SetCompatibleTextRenderingDefault(false);
2828
using (IApplicationContext ctx = ContextRegistry.GetContext())
@@ -34,13 +34,13 @@ static void Main()
3434
}
3535
catch (Exception e)
3636
{
37-
log.Error("Spring.MsmqQuickStart.Client is broken.", e);
37+
log.LogError(e, "Spring.MsmqQuickStart.Client is broken.");
3838
}
3939
}
4040

4141
private static void ThreadException(object sender, ThreadExceptionEventArgs e)
4242
{
43-
log.Error("Uncaught application exception.", e.Exception);
43+
log.LogError(e.Exception, "Uncaught application exception.");
4444
Application.Exit();
4545
}
4646
}

examples/Spring/Spring.MsmqQuickStart/src/Spring/Spring.MsmqQuickStart.Client/UI/StockForm.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ private void OnSendTradeRequest(object sender, EventArgs e)
3434
//Instead a hardcoded trade request is created in the controller.
3535
tradeRequestStatusTextBox.Text = "Request Pending...";
3636
stockController.SendTradeRequest();
37-
log.Info("Sent trade request.");
37+
log.LogInformation("Sent trade request.");
3838
}
3939

4040
public void UpdateTrade(TradeResponse trade)

examples/Spring/Spring.MsmqQuickStart/src/Spring/Spring.MsmqQuickStart.Server/Gateways/MarketDataServiceGateway.cs

+3-3
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,9 @@ public void SendMarketData()
2929
while (true)
3030
{
3131
string data = GenerateFakeMarketData();
32-
log.Info("Sending market data.");
32+
log.LogInformation("Sending market data.");
3333
MessageQueueTemplate.ConvertAndSend(data);
34-
log.Info("Sleeping " + sleepTimeInSeconds + " seconds before sending more market data.");
34+
log.LogInformation("Sleeping {SleepTimeSeconds} seconds before sending more market data.", sleepTimeInSeconds);
3535
Thread.Sleep(sleepTimeInSeconds);
3636
}
3737
}
@@ -59,4 +59,4 @@ private double Gaussian()
5959
//y2 = x2 * w;
6060
}
6161
}
62-
}
62+
}

examples/Spring/Spring.MsmqQuickStart/src/Spring/Spring.MsmqQuickStart.Server/Handlers/StockAppHandler.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ public StockAppHandler(IExecutionVenueService executionVenueService, ICreditChec
2626

2727
public TradeResponse Handle(TradeRequest tradeRequest)
2828
{
29-
log.Info("received trade request - sleeping 2s to simulate long-running task");
29+
log.LogInformation("received trade request - sleeping 2s to simulate long-running task");
3030
TradeResponse tradeResponse;
3131
ArrayList errors = new ArrayList();
3232
if (creditCheckService.CanExecute(tradeRequest, errors))

examples/Spring/Spring.NmsQuickStart/src/Spring/Spring.NmsQuickStart.Client/Handlers/StockAppHandler.cs

+3-3
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ public StockController StockController
4444

4545
public void Handle(Hashtable data)
4646
{
47-
log.Info(string.Format("Received market data. Ticker = {0}, Price = {1}", data["TICKER"], data["PRICE"]));
47+
log.LogInformation("Received market data. Ticker = {Ticker}, Price = {Price}", data["TICKER"], data["PRICE"]);
4848

4949
// forward to controller to update view
5050
stockController.UpdateMarketData(data);
@@ -54,13 +54,13 @@ public void Handle(Hashtable data)
5454

5555
public void Handle(TradeResponse tradeResponse)
5656
{
57-
log.Info(string.Format("Received trade resonse. Ticker = {0}, Price = {1}", tradeResponse.Ticker, tradeResponse.Price));
57+
log.LogInformation("Received trade response. Ticker = {TradeResponseTicker}, Price = {TradeResponsePrice}", tradeResponse.Ticker, tradeResponse.Price);
5858
stockController.UpdateTrade(tradeResponse);
5959
}
6060

6161
public void Handle(object catchAllObject)
6262
{
63-
log.Error("could not handle object of type = " + catchAllObject.GetType());
63+
log.LogError("could not handle object of type = {ObjectType}", catchAllObject.GetType());
6464
}
6565
}
6666
}

examples/Spring/Spring.NmsQuickStart/src/Spring/Spring.NmsQuickStart.Client/UI/StockForm.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ private void OnSendTradeRequest(object sender, EventArgs e)
5555
//Instead a hardcoded trade request is created in the controller.
5656
tradeRequestStatusTextBox.Text = "Request Pending...";
5757
stockController.SendTradeRequest();
58-
log.Info("Sent trade request.");
58+
log.LogInformation("Sent trade request.");
5959
}
6060

6161
public void UpdateTrade(TradeResponse trade)

examples/Spring/Spring.NmsQuickStart/src/Spring/Spring.NmsQuickStart.Server/Gateways/MarketDataServiceGateway.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,9 @@ public void SendMarketData()
2929
while (true)
3030
{
3131
IDictionary data = GenerateFakeMarketData();
32-
log.Info("Sending market data.");
32+
log.LogInformation("Sending market data.");
3333
NmsTemplate.ConvertAndSend(data);
34-
log.Info("Sleeping " + sleepTimeInSeconds + " seconds before sending more market data.");
34+
log.LogInformation("Sleeping {SleepTimeInSeconds} seconds before sending more market data.", sleepTimeInSeconds);
3535
Thread.Sleep(sleepTimeInSeconds);
3636
}
3737
}

examples/Spring/Spring.NmsQuickStart/test/Spring/Spring.NmsQuickStart.Tests/Spring.NmsQuickStart.Tests.csproj

-2
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
<DefineConstants>TRACE;DEBUG;NET_4_0</DefineConstants>
1515
<ErrorReport>prompt</ErrorReport>
1616
<WarningLevel>4</WarningLevel>
17-
<CodeAnalysisRuleSet>AllRules.ruleset</CodeAnalysisRuleSet>
1817
</PropertyGroup>
1918
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
2019
<DebugType>pdbonly</DebugType>
@@ -23,7 +22,6 @@
2322
<DefineConstants>TRACE;NET_4_0</DefineConstants>
2423
<ErrorReport>prompt</ErrorReport>
2524
<WarningLevel>4</WarningLevel>
26-
<CodeAnalysisRuleSet>AllRules.ruleset</CodeAnalysisRuleSet>
2725
</PropertyGroup>
2826
<PropertyGroup>
2927
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>

src/Spring/Spring.Aop/Aop/Framework/Adapter/ThrowsAdviceInterceptor.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ private void MapAllExceptionHandlingMethods(object advice)
165165

166166
if(log.IsEnabled(LogLevel.Debug))
167167
{
168-
log.Debug("Found exception handler method: " + method);
168+
log.LogDebug("Found exception handler method: " + method);
169169
}
170170

171171
#endregion
@@ -266,7 +266,7 @@ private MethodInfo GetExceptionHandler(Exception exception)
266266

267267
if(log.IsEnabled(LogLevel.Debug))
268268
{
269-
log.Debug("Trying to find handler for exception of type [" + exception.GetType().Name + "].");
269+
log.LogDebug("Trying to find handler for exception of type [" + exception.GetType().Name + "].");
270270
}
271271

272272
#endregion

src/Spring/Spring.Aop/Aop/Framework/AutoProxy/AbstractAdvisorAutoProxyCreator.cs

+3-3
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ protected virtual List<IAdvisor> FindAdvisorsThatCanApply(List<IAdvisor> candida
185185
{
186186
if (logger.IsEnabled(LogLevel.Information))
187187
{
188-
logger.Info($"Candidate advisor [{candidate}] accepted for targetType [{targetType}]");
188+
logger.LogInformation($"Candidate advisor [{candidate}] accepted for targetType [{targetType}]");
189189
}
190190
eligibleAdvisors.Add(candidate);
191191
}
@@ -200,15 +200,15 @@ protected virtual List<IAdvisor> FindAdvisorsThatCanApply(List<IAdvisor> candida
200200
{
201201
if (logger.IsEnabled(LogLevel.Information))
202202
{
203-
logger.Info($"Candidate advisor [{candidate}] accepted for targetType [{targetType}]");
203+
logger.LogInformation($"Candidate advisor [{candidate}] accepted for targetType [{targetType}]");
204204
}
205205
eligibleAdvisors.Add(candidate);
206206
}
207207
else
208208
{
209209
if (logger.IsEnabled(LogLevel.Information))
210210
{
211-
logger.Info($"Candidate advisor [{candidate}] rejected for targetType [{targetType}]");
211+
logger.LogInformation($"Candidate advisor [{candidate}] rejected for targetType [{targetType}]");
212212
}
213213
}
214214
}

src/Spring/Spring.Aop/Aop/Framework/AutoProxy/AbstractAutoProxyCreator.cs

+6-6
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,7 @@ public virtual object PostProcessAfterInitialization(object obj, string objectNa
238238
{
239239
if (logger.IsEnabled(LogLevel.Debug))
240240
{
241-
logger.Debug(string.Format("Did not attempt to autoproxy infrastructure type [{0}]", objectType));
241+
logger.LogDebug(string.Format("Did not attempt to autoproxy infrastructure type [{0}]", objectType));
242242
}
243243

244244
nonAdvisedObjects.Add(cacheKey);
@@ -249,7 +249,7 @@ public virtual object PostProcessAfterInitialization(object obj, string objectNa
249249
{
250250
if (logger.IsEnabled(LogLevel.Debug))
251251
{
252-
logger.Debug(string.Format("Skipping type [{0}]", objectType));
252+
logger.LogDebug(string.Format("Skipping type [{0}]", objectType));
253253
}
254254

255255
nonAdvisedObjects.Add(cacheKey);
@@ -390,7 +390,7 @@ protected virtual ITargetSource GetCustomTargetSource(Type objectType, string na
390390
// found a match
391391
if (logger.IsEnabled(LogLevel.Information))
392392
{
393-
logger.Info(string.Format("TargetSourceCreator [{0} found custom TargetSource for object with objectName '{1}'", tsc, name));
393+
logger.LogInformation(string.Format("TargetSourceCreator [{0} found custom TargetSource for object with objectName '{1}'", tsc, name));
394394
}
395395
return ts;
396396
}
@@ -514,7 +514,7 @@ protected virtual IList<IAdvisor> BuildAdvisors(string targetName, IList<object>
514514
{
515515
int nrOfCommonInterceptors = commonInterceptors != null ? commonInterceptors.Count : 0;
516516
int nrOfSpecificInterceptors = specificInterceptors != null ? specificInterceptors.Count : 0;
517-
logger.Info(string.Format("Creating implicit proxy for object '{0}' with {1} common interceptors and {2} specific interceptors", targetName, nrOfCommonInterceptors, nrOfSpecificInterceptors));
517+
logger.LogInformation(string.Format("Creating implicit proxy for object '{0}' with {1} common interceptors and {2} specific interceptors", targetName, nrOfCommonInterceptors, nrOfSpecificInterceptors));
518518
}
519519

520520

@@ -576,7 +576,7 @@ public object PostProcessBeforeInstantiation(Type objectType, string objectName)
576576
{
577577
if (logger.IsEnabled(LogLevel.Debug))
578578
{
579-
logger.Debug(string.Format("Did not attempt to autoproxy infrastructure type [{0}]", objectType));
579+
logger.LogDebug(string.Format("Did not attempt to autoproxy infrastructure type [{0}]", objectType));
580580
}
581581

582582
nonAdvisedObjects.Add(cacheKey);
@@ -587,7 +587,7 @@ public object PostProcessBeforeInstantiation(Type objectType, string objectName)
587587
{
588588
if (logger.IsEnabled(LogLevel.Debug))
589589
{
590-
logger.Debug(string.Format("Skipping type [{0}]", objectType));
590+
logger.LogDebug(string.Format("Skipping type [{0}]", objectType));
591591
}
592592

593593
nonAdvisedObjects.Add(cacheKey);

src/Spring/Spring.Aop/Aop/Framework/AutoProxy/ObjectFactoryAdvisorRetrievalHelper.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ public virtual List<IAdvisor> FindAdvisorObjects(Type targetType, string targetN
9090
{
9191
if (_log.IsEnabled(LogLevel.Debug))
9292
{
93-
_log.Debug(string.Format("Ignoring currently created advisor '{0}': exception message = {1}",
93+
_log.LogDebug(string.Format("Ignoring currently created advisor '{0}': exception message = {1}",
9494
name, ex.Message));
9595
}
9696
continue;

src/Spring/Spring.Aop/Aop/Framework/AutoProxy/Target/AbstractPrototypeTargetSourceCreator.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -63,14 +63,14 @@ public ITargetSource GetTargetSource(Type objectType, string name, IObjectFactor
6363
if (!(factory is IObjectDefinitionRegistry))
6464
{
6565
if (logger.IsEnabled(LogLevel.Warning))
66-
logger.Warn("Cannot do autopooling with a IObjectFactory that doesn't implement IObjectDefinitionRegistry");
66+
logger.LogWarning("Cannot do autopooling with a IObjectFactory that doesn't implement IObjectDefinitionRegistry");
6767
return null;
6868
}
6969
IObjectDefinitionRegistry definitionRegistry = (IObjectDefinitionRegistry) factory;
7070
RootObjectDefinition definition = (RootObjectDefinition) definitionRegistry.GetObjectDefinition(name);
7171

7272
if (logger.IsEnabled(LogLevel.Information))
73-
logger.Info("Configuring AbstractPrototypeBasedTargetSource...");
73+
logger.LogInformation("Configuring AbstractPrototypeBasedTargetSource...");
7474

7575
// Infinite cycle will result if we don't use a different factory,
7676
// because a GetObject() call with this objectName will go through the autoproxy

0 commit comments

Comments
 (0)