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

Commit53cbb75

Browse files
committed
CallSiteLayoutRenderer - Obsolete CleanNamesOfAnonymousDelegates + CleanNamesOfAsyncContinuation
1 parent82101e1 commit53cbb75

File tree

2 files changed

+19
-124
lines changed

2 files changed

+19
-124
lines changed

‎src/NLog/LayoutRenderers/CallSiteLayoutRenderer.cs‎

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

3434
namespaceNLog.LayoutRenderers
3535
{
36+
usingSystem;
37+
usingSystem.ComponentModel;
3638
usingSystem.IO;
3739
usingSystem.Text;
3840
usingNLog.Config;
@@ -75,6 +77,8 @@ public class CallSiteLayoutRenderer : LayoutRenderer, IUsesStackTrace
7577
/// </summary>
7678
/// <remarks>Default: <see langword="true"/></remarks>
7779
/// <docgen category='Layout Options' order='10' />
80+
[Obsolete("Should always be enabled. Marked obsolete with v6.1")]
81+
[EditorBrowsable(EditorBrowsableState.Never)]
7882
publicboolCleanNamesOfAnonymousDelegates{get;set;}=true;
7983

8084
/// <summary>
@@ -83,6 +87,8 @@ public class CallSiteLayoutRenderer : LayoutRenderer, IUsesStackTrace
8387
/// </summary>
8488
/// <remarks>Default: <see langword="true"/></remarks>
8589
/// <docgen category='Layout Options' order='10' />
90+
[Obsolete("Should always be enabled. Marked obsolete with v6.1")]
91+
[EditorBrowsable(EditorBrowsableState.Never)]
8692
publicboolCleanNamesOfAsyncContinuations{get;set;}=true;
8793

8894
/// <summary>
@@ -141,13 +147,17 @@ protected override void Append(StringBuilder builder, LogEventInfo logEvent)
141147

142148
if(ClassName)
143149
{
150+
#pragma warning disableCS0618// Type or member is obsolete
144151
varclassName=logEventCallSize.GetCallerClassName(method,IncludeNamespace,CleanNamesOfAsyncContinuations,CleanNamesOfAnonymousDelegates);
152+
#pragma warning restoreCS0618// Type or member is obsolete
145153
builder.Append(string.IsNullOrEmpty(className)?"<no type>":className);
146154
}
147155

148156
if(MethodName)
149157
{
158+
#pragma warning disableCS0618// Type or member is obsolete
150159
varmethodName=logEventCallSize.GetCallerMethodName(method,false,CleanNamesOfAsyncContinuations,CleanNamesOfAnonymousDelegates);
160+
#pragma warning restoreCS0618// Type or member is obsolete
151161
if(ClassName)
152162
{
153163
builder.Append('.');
@@ -192,7 +202,9 @@ private void AppendExceptionCallSite(StringBuilder builder, LogEventInfo logEven
192202
{
193203
if(ClassName)
194204
{
205+
#pragma warning disableCS0618// Type or member is obsolete
195206
varclassName=StackTraceUsageUtils.GetStackFrameMethodClassName(targetSite,true,CleanNamesOfAsyncContinuations,CleanNamesOfAnonymousDelegates);
207+
#pragma warning restoreCS0618// Type or member is obsolete
196208
builder.Append(className);
197209
}
198210

@@ -202,7 +214,9 @@ private void AppendExceptionCallSite(StringBuilder builder, LogEventInfo logEven
202214
{
203215
builder.Append('.');
204216
}
217+
#pragma warning disableCS0618// Type or member is obsolete
205218
varmethodName=StackTraceUsageUtils.GetStackFrameMethodName(targetSite,false,CleanNamesOfAsyncContinuations,CleanNamesOfAnonymousDelegates);
219+
#pragma warning restoreCS0618// Type or member is obsolete
206220
builder.Append(methodName);
207221
}
208222
}

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

Lines changed: 5 additions & 124 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,54 +407,12 @@ public void CleanMethodNamesOfAnonymousDelegatesTest()
407407
}
408408
}
409409

410-
[Fact]
411-
publicvoidDontCleanMethodNamesOfAnonymousDelegatesTest()
412-
{
413-
#if!NETFRAMEWORK
414-
if(IsLinux())
415-
{
416-
Console.WriteLine("[SKIP] DontCleanMethodNamesOfAnonymousDelegatesTest because unstable with NET8");
417-
return;
418-
}
419-
#endif
420-
421-
varlogFactory=newLogFactory().Setup().LoadConfigurationFromXml(@"
422-
<nlog>
423-
<targets><target name='debug' type='Debug' layout='${callsite:ClassName=false:CleanNamesOfAnonymousDelegates=false}' /></targets>
424-
<rules>
425-
<logger name='*' levels='Fatal' writeTo='debug' />
426-
</rules>
427-
</nlog>").LogFactory;
428-
429-
varlogger=logFactory.GetLogger("A");
430-
431-
booldone=false;
432-
ThreadPool.QueueUserWorkItem(
433-
state=>
434-
{
435-
logger.Fatal("message");
436-
done=true;
437-
},
438-
null);
439-
440-
while(done==false)
441-
{
442-
Thread.Sleep(10);
443-
}
444-
445-
if(done==true)
446-
{
447-
stringlastMessage=GetDebugLastMessage("debug",logFactory);
448-
Assert.StartsWith("<DontCleanMethodNamesOfAnonymousDelegatesTest>",lastMessage);
449-
}
450-
}
451-
452410
[Fact]
453411
publicvoidCleanClassNamesOfAnonymousDelegatesTest()
454412
{
455413
varlogFactory=newLogFactory().Setup().LoadConfigurationFromXml(@"
456414
<nlog>
457-
<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>
458416
<rules>
459417
<logger name='*' levels='Fatal' writeTo='debug' />
460418
</rules>
@@ -482,53 +440,12 @@ public void CleanClassNamesOfAnonymousDelegatesTest()
482440
}
483441
}
484442

485-
[Fact]
486-
publicvoidDontCleanClassNamesOfAnonymousDelegatesTest()
487-
{
488-
#if!NETFRAMEWORK
489-
if(IsLinux())
490-
{
491-
Console.WriteLine("[SKIP] DontCleanClassNamesOfAnonymousDelegatesTest because unstable with NET8");
492-
return;
493-
}
494-
#endif
495-
496-
varlogFactory=newLogFactory().Setup().LoadConfigurationFromXml(@"
497-
<nlog>
498-
<targets><target name='debug' type='Debug' layout='${callsite:ClassName=true:MethodName=false:CleanNamesOfAnonymousDelegates=false}' /></targets>
499-
<rules>
500-
<logger name='*' levels='Fatal' writeTo='debug' />
501-
</rules>
502-
</nlog>").LogFactory;
503-
504-
varlogger=logFactory.GetLogger("A");
505-
506-
booldone=false;
507-
ThreadPool.QueueUserWorkItem(
508-
state=>
509-
{
510-
logger.Fatal("message");
511-
done=true;
512-
},
513-
null);
514-
515-
while(done==false)
516-
{
517-
Thread.Sleep(10);
518-
}
519-
520-
if(done==true)
521-
{
522-
logFactory.AssertDebugLastMessageContains("+<>");
523-
}
524-
}
525-
526443
[Fact]
527444
publicvoidWhen_NotIncludeNameSpace_Then_CleanAnonymousDelegateClassNameShouldReturnParentClassName()
528445
{
529446
varlogFactory=newLogFactory().Setup().LoadConfigurationFromXml(@"
530447
<nlog>
531-
<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>
532449
<rules>
533450
<logger name='*' levels='Fatal' writeTo='debug' />
534451
</rules>
@@ -1247,7 +1164,7 @@ public void LogAfterTaskRunAwait_CleanNamesOfAsyncContinuationsIsTrue_ShouldClea
12471164

12481165
varlogFactory=newLogFactory().Setup().LoadConfigurationFromXml(@"
12491166
<nlog>
1250-
<targets><target name='debug' type='Debug' layout='${callsite:classname=false:cleannamesofasynccontinuations=true}' /></targets>
1167+
<targets><target name='debug' type='Debug' layout='${callsite:classname=false}' /></targets>
12511168
<rules>
12521169
<logger name='*' levels='Debug' writeTo='debug' />
12531170
</rules>
@@ -1277,7 +1194,7 @@ public void LogAfterTaskRunAwait_CleanNamesOfAsyncContinuationsIsTrue_ShouldClea
12771194

12781195
varlogFactory=newLogFactory().Setup().LoadConfigurationFromXml(@"
12791196
<nlog>
1280-
<targets><target name='debug' type='Debug' layout='${callsite:classname=true:includenamespace=true:cleannamesofasynccontinuations=true:cleanNamesOfAnonymousDelegates=true}' /></targets>
1197+
<targets><target name='debug' type='Debug' layout='${callsite:classname=true:includenamespace=true}' /></targets>
12811198
<rules>
12821199
<logger name='*' levels='Debug' writeTo='debug' />
12831200
</rules>
@@ -1299,42 +1216,6 @@ public void LogAfterTaskRunAwait_CleanNamesOfAsyncContinuationsIsTrue_ShouldClea
12991216
logFactory.AssertDebugLastMessage($"{typeof(InnerClassAsyncMethod6).ToString()}.AsyncMethod6b");
13001217
}
13011218

1302-
#ifNET35
1303-
[Fact(Skip="NET35 not supporting async callstack")]
1304-
#elifMONO
1305-
[Fact(Skip="Not working under MONO - not sure if unit test is wrong, or the code")]
1306-
#else
1307-
[Fact]
1308-
#endif
1309-
publicvoidLogAfterTaskRunAwait_CleanNamesOfAsyncContinuationsIsFalse_ShouldNotCleanNames()
1310-
{
1311-
#if!NETFRAMEWORK
1312-
if(IsLinux())
1313-
{
1314-
Console.WriteLine("[SKIP] LogAfterTaskRunAwait_CleanNamesOfAsyncContinuationsIsFalse_ShouldNotCleanNames because unstable with NET8");
1315-
return;
1316-
}
1317-
#endif
1318-
1319-
varlogFactory=newLogFactory().Setup().LoadConfigurationFromXml(@"
1320-
<nlog>
1321-
<targets><target name='debug' type='Debug' layout='${callsite:includenamespace=true:cleannamesofasynccontinuations=false}' /></targets>
1322-
<rules>
1323-
<logger name='*' levels='Debug' writeTo='debug' />
1324-
</rules>
1325-
</nlog>").LogFactory;
1326-
1327-
Task.Run(async()=>
1328-
{
1329-
awaitAMinimalAsyncMethod();
1330-
varlogger=logFactory.GetCurrentClassLogger();
1331-
logger.Debug("dude");
1332-
}).Wait();
1333-
1334-
logFactory.AssertDebugLastMessageContains("NLog.UnitTests.LayoutRenderers.CallSiteTests");
1335-
logFactory.AssertDebugLastMessageContains("MoveNext");
1336-
}
1337-
13381219
privateclassInnerClassAsyncMethod6
13391220
{
13401221
publicvirtualasyncTaskAsyncMethod6a(LogFactorylogFactory)

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp