Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings
/NLogPublic

Commit9e69dfc

Browse files
committed
CallSiteLayoutRenderer - Obsolete CleanNamesOfAnonymousDelegates + CleanNamesOfAsyncContinuation
1 parentc23cb69 commit9e69dfc

File tree

2 files changed

+16
-100
lines changed

2 files changed

+16
-100
lines changed

‎src/NLog/LayoutRenderers/CallSiteLayoutRenderer.cs‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333

3434
namespaceNLog.LayoutRenderers
3535
{
36+
usingSystem;
3637
usingSystem.IO;
3738
usingSystem.Text;
3839
usingNLog.Config;
@@ -75,6 +76,7 @@ public class CallSiteLayoutRenderer : LayoutRenderer, IUsesStackTrace
7576
/// </summary>
7677
/// <remarks>Default: <see langword="true"/></remarks>
7778
/// <docgen category='Layout Options' order='10' />
79+
[Obsolete("Should always be enabled. Marked obsolete with v6.1")]
7880
publicboolCleanNamesOfAnonymousDelegates{get;set;}=true;
7981

8082
/// <summary>
@@ -83,6 +85,7 @@ public class CallSiteLayoutRenderer : LayoutRenderer, IUsesStackTrace
8385
/// </summary>
8486
/// <remarks>Default: <see langword="true"/></remarks>
8587
/// <docgen category='Layout Options' order='10' />
88+
[Obsolete("Should always be enabled. Marked obsolete with v6.1")]
8689
publicboolCleanNamesOfAsyncContinuations{get;set;}=true;
8790

8891
/// <summary>
@@ -141,13 +144,17 @@ protected override void Append(StringBuilder builder, LogEventInfo logEvent)
141144

142145
if(ClassName)
143146
{
147+
#pragma warning disableCS0618// Type or member is obsolete
144148
varclassName=logEventCallSize.GetCallerClassName(method,IncludeNamespace,CleanNamesOfAsyncContinuations,CleanNamesOfAnonymousDelegates);
149+
#pragma warning restoreCS0618// Type or member is obsolete
145150
builder.Append(string.IsNullOrEmpty(className)?"<no type>":className);
146151
}
147152

148153
if(MethodName)
149154
{
155+
#pragma warning disableCS0618// Type or member is obsolete
150156
varmethodName=logEventCallSize.GetCallerMethodName(method,false,CleanNamesOfAsyncContinuations,CleanNamesOfAnonymousDelegates);
157+
#pragma warning restoreCS0618// Type or member is obsolete
151158
if(ClassName)
152159
{
153160
builder.Append('.');
@@ -192,7 +199,9 @@ private void AppendExceptionCallSite(StringBuilder builder, LogEventInfo logEven
192199
{
193200
if(ClassName)
194201
{
202+
#pragma warning disableCS0618// Type or member is obsolete
195203
varclassName=StackTraceUsageUtils.GetStackFrameMethodClassName(targetSite,true,CleanNamesOfAsyncContinuations,CleanNamesOfAnonymousDelegates);
204+
#pragma warning restoreCS0618// Type or member is obsolete
196205
builder.Append(className);
197206
}
198207

@@ -202,7 +211,9 @@ private void AppendExceptionCallSite(StringBuilder builder, LogEventInfo logEven
202211
{
203212
builder.Append('.');
204213
}
214+
#pragma warning disableCS0618// Type or member is obsolete
205215
varmethodName=StackTraceUsageUtils.GetStackFrameMethodName(targetSite,false,CleanNamesOfAsyncContinuations,CleanNamesOfAnonymousDelegates);
216+
#pragma warning restoreCS0618// Type or member is obsolete
206217
builder.Append(methodName);
207218
}
208219
}

‎tests/NLog.UnitTests/LayoutRenderers/CallSiteTests.cs‎

Lines changed: 5 additions & 100 deletions
Original file line numberDiff line numberDiff line change
@@ -379,7 +379,7 @@ public void CleanMethodNamesOfAnonymousDelegatesTest()
379379
{
380380
varlogFactory=newLogFactory().Setup().LoadConfigurationFromXml(@"
381381
<nlog>
382-
<targets><target name='debug' type='Debug' layout='${callsite:ClassName=false:CleanNamesOfAnonymousDelegates=true}' /></targets>
382+
<targets><target name='debug' type='Debug' layout='${callsite:ClassName=false}' /></targets>
383383
<rules>
384384
<logger name='*' levels='Fatal' writeTo='debug' />
385385
</rules>
@@ -407,46 +407,12 @@ public void CleanMethodNamesOfAnonymousDelegatesTest()
407407
}
408408
}
409409

410-
[Fact]
411-
publicvoidDontCleanMethodNamesOfAnonymousDelegatesTest()
412-
{
413-
varlogFactory=newLogFactory().Setup().LoadConfigurationFromXml(@"
414-
<nlog>
415-
<targets><target name='debug' type='Debug' layout='${callsite:ClassName=false:CleanNamesOfAnonymousDelegates=false}' /></targets>
416-
<rules>
417-
<logger name='*' levels='Fatal' writeTo='debug' />
418-
</rules>
419-
</nlog>").LogFactory;
420-
421-
varlogger=logFactory.GetLogger("A");
422-
423-
booldone=false;
424-
ThreadPool.QueueUserWorkItem(
425-
state=>
426-
{
427-
logger.Fatal("message");
428-
done=true;
429-
},
430-
null);
431-
432-
while(done==false)
433-
{
434-
Thread.Sleep(10);
435-
}
436-
437-
if(done==true)
438-
{
439-
stringlastMessage=GetDebugLastMessage("debug",logFactory);
440-
Assert.StartsWith("<DontCleanMethodNamesOfAnonymousDelegatesTest>",lastMessage);
441-
}
442-
}
443-
444410
[Fact]
445411
publicvoidCleanClassNamesOfAnonymousDelegatesTest()
446412
{
447413
varlogFactory=newLogFactory().Setup().LoadConfigurationFromXml(@"
448414
<nlog>
449-
<targets><target name='debug' type='Debug' layout='${callsite:ClassName=true:MethodName=false:CleanNamesOfAnonymousDelegates=true}' /></targets>
415+
<targets><target name='debug' type='Debug' layout='${callsite:ClassName=true:MethodName=false}' /></targets>
450416
<rules>
451417
<logger name='*' levels='Fatal' writeTo='debug' />
452418
</rules>
@@ -474,45 +440,12 @@ public void CleanClassNamesOfAnonymousDelegatesTest()
474440
}
475441
}
476442

477-
[Fact]
478-
publicvoidDontCleanClassNamesOfAnonymousDelegatesTest()
479-
{
480-
varlogFactory=newLogFactory().Setup().LoadConfigurationFromXml(@"
481-
<nlog>
482-
<targets><target name='debug' type='Debug' layout='${callsite:ClassName=true:MethodName=false:CleanNamesOfAnonymousDelegates=false}' /></targets>
483-
<rules>
484-
<logger name='*' levels='Fatal' writeTo='debug' />
485-
</rules>
486-
</nlog>").LogFactory;
487-
488-
varlogger=logFactory.GetLogger("A");
489-
490-
booldone=false;
491-
ThreadPool.QueueUserWorkItem(
492-
state=>
493-
{
494-
logger.Fatal("message");
495-
done=true;
496-
},
497-
null);
498-
499-
while(done==false)
500-
{
501-
Thread.Sleep(10);
502-
}
503-
504-
if(done==true)
505-
{
506-
logFactory.AssertDebugLastMessageContains("+<>");
507-
}
508-
}
509-
510443
[Fact]
511444
publicvoidWhen_NotIncludeNameSpace_Then_CleanAnonymousDelegateClassNameShouldReturnParentClassName()
512445
{
513446
varlogFactory=newLogFactory().Setup().LoadConfigurationFromXml(@"
514447
<nlog>
515-
<targets><target name='debug' type='Debug' layout='${callsite:ClassName=true:MethodName=false:IncludeNamespace=false:CleanNamesOfAnonymousDelegates=true}' /></targets>
448+
<targets><target name='debug' type='Debug' layout='${callsite:ClassName=true:MethodName=false:IncludeNamespace=false}' /></targets>
516449
<rules>
517450
<logger name='*' levels='Fatal' writeTo='debug' />
518451
</rules>
@@ -1232,7 +1165,7 @@ public void LogAfterTaskRunAwait_CleanNamesOfAsyncContinuationsIsTrue_ShouldClea
12321165

12331166
varlogFactory=newLogFactory().Setup().LoadConfigurationFromXml(@"
12341167
<nlog>
1235-
<targets><target name='debug' type='Debug' layout='${callsite:classname=false:cleannamesofasynccontinuations=true}' /></targets>
1168+
<targets><target name='debug' type='Debug' layout='${callsite:classname=false}' /></targets>
12361169
<rules>
12371170
<logger name='*' levels='Debug' writeTo='debug' />
12381171
</rules>
@@ -1262,7 +1195,7 @@ public void LogAfterTaskRunAwait_CleanNamesOfAsyncContinuationsIsTrue_ShouldClea
12621195

12631196
varlogFactory=newLogFactory().Setup().LoadConfigurationFromXml(@"
12641197
<nlog>
1265-
<targets><target name='debug' type='Debug' layout='${callsite:classname=true:includenamespace=true:cleannamesofasynccontinuations=true:cleanNamesOfAnonymousDelegates=true}' /></targets>
1198+
<targets><target name='debug' type='Debug' layout='${callsite:classname=true:includenamespace=true}' /></targets>
12661199
<rules>
12671200
<logger name='*' levels='Debug' writeTo='debug' />
12681201
</rules>
@@ -1284,34 +1217,6 @@ public void LogAfterTaskRunAwait_CleanNamesOfAsyncContinuationsIsTrue_ShouldClea
12841217
logFactory.AssertDebugLastMessage($"{typeof(InnerClassAsyncMethod6).ToString()}.AsyncMethod6b");
12851218
}
12861219

1287-
#ifNET35
1288-
[Fact(Skip="NET35 not supporting async callstack")]
1289-
#elifMONO
1290-
[Fact(Skip="Not working under MONO - not sure if unit test is wrong, or the code")]
1291-
#else
1292-
[Fact]
1293-
#endif
1294-
publicvoidLogAfterTaskRunAwait_CleanNamesOfAsyncContinuationsIsFalse_ShouldNotCleanNames()
1295-
{
1296-
varlogFactory=newLogFactory().Setup().LoadConfigurationFromXml(@"
1297-
<nlog>
1298-
<targets><target name='debug' type='Debug' layout='${callsite:includenamespace=true:cleannamesofasynccontinuations=false}' /></targets>
1299-
<rules>
1300-
<logger name='*' levels='Debug' writeTo='debug' />
1301-
</rules>
1302-
</nlog>").LogFactory;
1303-
1304-
Task.Run(async()=>
1305-
{
1306-
awaitAMinimalAsyncMethod();
1307-
varlogger=logFactory.GetCurrentClassLogger();
1308-
logger.Debug("dude");
1309-
}).Wait();
1310-
1311-
logFactory.AssertDebugLastMessageContains("NLog.UnitTests.LayoutRenderers.CallSiteTests");
1312-
logFactory.AssertDebugLastMessageContains("MoveNext");
1313-
}
1314-
13151220
privateclassInnerClassAsyncMethod6
13161221
{
13171222
publicvirtualasyncTaskAsyncMethod6a(LogFactorylogFactory)

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp