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

CallSiteLayoutRenderer - Obsolete CleanNamesOfAnonymousDelegates + CleanNamesOfAsyncContinuation#5949

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Open
snakefoot wants to merge1 commit intoNLog:dev
base:dev
Choose a base branch
Loading
fromsnakefoot:cleanup_obsolete
Open
Show file tree
Hide file tree
Changes fromall commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletionssrc/NLog/LayoutRenderers/CallSiteLayoutRenderer.cs
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -33,6 +33,8 @@

namespace NLog.LayoutRenderers
{
using System;
using System.ComponentModel;
using System.IO;
using System.Text;
using NLog.Config;
Expand DownExpand Up@@ -75,6 +77,8 @@ public class CallSiteLayoutRenderer : LayoutRenderer, IUsesStackTrace
/// </summary>
/// <remarks>Default: <see langword="true"/></remarks>
/// <docgen category='Layout Options' order='10' />
[Obsolete("Should always be enabled. Marked obsolete with v6.1")]
[EditorBrowsable(EditorBrowsableState.Never)]
public bool CleanNamesOfAnonymousDelegates { get; set; } = true;

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

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

if (ClassName)
{
#pragma warning disable CS0618 // Type or member is obsolete
var className = logEventCallSize.GetCallerClassName(method, IncludeNamespace, CleanNamesOfAsyncContinuations, CleanNamesOfAnonymousDelegates);
#pragma warning restore CS0618 // Type or member is obsolete
builder.Append(string.IsNullOrEmpty(className) ? "<no type>" : className);
}

if (MethodName)
{
#pragma warning disable CS0618 // Type or member is obsolete
var methodName = logEventCallSize.GetCallerMethodName(method, false, CleanNamesOfAsyncContinuations, CleanNamesOfAnonymousDelegates);
#pragma warning restore CS0618 // Type or member is obsolete
if (ClassName)
{
builder.Append('.');
Expand DownExpand Up@@ -192,7 +202,9 @@ private void AppendExceptionCallSite(StringBuilder builder, LogEventInfo logEven
{
if (ClassName)
{
#pragma warning disable CS0618 // Type or member is obsolete
var className = StackTraceUsageUtils.GetStackFrameMethodClassName(targetSite, true, CleanNamesOfAsyncContinuations, CleanNamesOfAnonymousDelegates);
#pragma warning restore CS0618 // Type or member is obsolete
builder.Append(className);
}

Expand All@@ -202,7 +214,9 @@ private void AppendExceptionCallSite(StringBuilder builder, LogEventInfo logEven
{
builder.Append('.');
}
#pragma warning disable CS0618 // Type or member is obsolete
var methodName = StackTraceUsageUtils.GetStackFrameMethodName(targetSite, false, CleanNamesOfAsyncContinuations, CleanNamesOfAnonymousDelegates);
#pragma warning restore CS0618 // Type or member is obsolete
builder.Append(methodName);
}
}
Expand Down
129 changes: 5 additions & 124 deletionstests/NLog.UnitTests/LayoutRenderers/CallSiteTests.cs
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -379,7 +379,7 @@ public void CleanMethodNamesOfAnonymousDelegatesTest()
{
var logFactory = new LogFactory().Setup().LoadConfigurationFromXml(@"
<nlog>
<targets><target name='debug' type='Debug' layout='${callsite:ClassName=false:CleanNamesOfAnonymousDelegates=true}' /></targets>
<targets><target name='debug' type='Debug' layout='${callsite:ClassName=false}' /></targets>
<rules>
<logger name='*' levels='Fatal' writeTo='debug' />
</rules>
Expand DownExpand Up@@ -407,54 +407,12 @@ public void CleanMethodNamesOfAnonymousDelegatesTest()
}
}

[Fact]
public void DontCleanMethodNamesOfAnonymousDelegatesTest()
{
#if !NETFRAMEWORK
if (IsLinux())
{
Console.WriteLine("[SKIP] DontCleanMethodNamesOfAnonymousDelegatesTest because unstable with NET8");
return;
}
#endif

var logFactory = new LogFactory().Setup().LoadConfigurationFromXml(@"
<nlog>
<targets><target name='debug' type='Debug' layout='${callsite:ClassName=false:CleanNamesOfAnonymousDelegates=false}' /></targets>
<rules>
<logger name='*' levels='Fatal' writeTo='debug' />
</rules>
</nlog>").LogFactory;

var logger = logFactory.GetLogger("A");

bool done = false;
ThreadPool.QueueUserWorkItem(
state =>
{
logger.Fatal("message");
done = true;
},
null);

while (done == false)
{
Thread.Sleep(10);
}

if (done == true)
{
string lastMessage = GetDebugLastMessage("debug", logFactory);
Assert.StartsWith("<DontCleanMethodNamesOfAnonymousDelegatesTest>", lastMessage);
}
}

[Fact]
public void CleanClassNamesOfAnonymousDelegatesTest()
{
var logFactory = new LogFactory().Setup().LoadConfigurationFromXml(@"
<nlog>
<targets><target name='debug' type='Debug' layout='${callsite:ClassName=true:MethodName=false:CleanNamesOfAnonymousDelegates=true}' /></targets>
<targets><target name='debug' type='Debug' layout='${callsite:ClassName=true:MethodName=false}' /></targets>
<rules>
<logger name='*' levels='Fatal' writeTo='debug' />
</rules>
Expand DownExpand Up@@ -482,53 +440,12 @@ public void CleanClassNamesOfAnonymousDelegatesTest()
}
}

[Fact]
public void DontCleanClassNamesOfAnonymousDelegatesTest()
{
#if !NETFRAMEWORK
if (IsLinux())
{
Console.WriteLine("[SKIP] DontCleanClassNamesOfAnonymousDelegatesTest because unstable with NET8");
return;
}
#endif

var logFactory = new LogFactory().Setup().LoadConfigurationFromXml(@"
<nlog>
<targets><target name='debug' type='Debug' layout='${callsite:ClassName=true:MethodName=false:CleanNamesOfAnonymousDelegates=false}' /></targets>
<rules>
<logger name='*' levels='Fatal' writeTo='debug' />
</rules>
</nlog>").LogFactory;

var logger = logFactory.GetLogger("A");

bool done = false;
ThreadPool.QueueUserWorkItem(
state =>
{
logger.Fatal("message");
done = true;
},
null);

while (done == false)
{
Thread.Sleep(10);
}

if (done == true)
{
logFactory.AssertDebugLastMessageContains("+<>");
}
}

[Fact]
public void When_NotIncludeNameSpace_Then_CleanAnonymousDelegateClassNameShouldReturnParentClassName()
{
var logFactory = new LogFactory().Setup().LoadConfigurationFromXml(@"
<nlog>
<targets><target name='debug' type='Debug' layout='${callsite:ClassName=true:MethodName=false:IncludeNamespace=false:CleanNamesOfAnonymousDelegates=true}' /></targets>
<targets><target name='debug' type='Debug' layout='${callsite:ClassName=true:MethodName=false:IncludeNamespace=false}' /></targets>
<rules>
<logger name='*' levels='Fatal' writeTo='debug' />
</rules>
Expand DownExpand Up@@ -1247,7 +1164,7 @@ public void LogAfterTaskRunAwait_CleanNamesOfAsyncContinuationsIsTrue_ShouldClea

var logFactory = new LogFactory().Setup().LoadConfigurationFromXml(@"
<nlog>
<targets><target name='debug' type='Debug' layout='${callsite:classname=false:cleannamesofasynccontinuations=true}' /></targets>
<targets><target name='debug' type='Debug' layout='${callsite:classname=false}' /></targets>
<rules>
<logger name='*' levels='Debug' writeTo='debug' />
</rules>
Expand DownExpand Up@@ -1277,7 +1194,7 @@ public void LogAfterTaskRunAwait_CleanNamesOfAsyncContinuationsIsTrue_ShouldClea

var logFactory = new LogFactory().Setup().LoadConfigurationFromXml(@"
<nlog>
<targets><target name='debug' type='Debug' layout='${callsite:classname=true:includenamespace=true:cleannamesofasynccontinuations=true:cleanNamesOfAnonymousDelegates=true}' /></targets>
<targets><target name='debug' type='Debug' layout='${callsite:classname=true:includenamespace=true}' /></targets>
<rules>
<logger name='*' levels='Debug' writeTo='debug' />
</rules>
Expand All@@ -1299,42 +1216,6 @@ public void LogAfterTaskRunAwait_CleanNamesOfAsyncContinuationsIsTrue_ShouldClea
logFactory.AssertDebugLastMessage($"{typeof(InnerClassAsyncMethod6).ToString()}.AsyncMethod6b");
}

#if NET35
[Fact(Skip = "NET35 not supporting async callstack")]
#elif MONO
[Fact(Skip = "Not working under MONO - not sure if unit test is wrong, or the code")]
#else
[Fact]
#endif
public void LogAfterTaskRunAwait_CleanNamesOfAsyncContinuationsIsFalse_ShouldNotCleanNames()
{
#if !NETFRAMEWORK
if (IsLinux())
{
Console.WriteLine("[SKIP] LogAfterTaskRunAwait_CleanNamesOfAsyncContinuationsIsFalse_ShouldNotCleanNames because unstable with NET8");
return;
}
#endif

var logFactory = new LogFactory().Setup().LoadConfigurationFromXml(@"
<nlog>
<targets><target name='debug' type='Debug' layout='${callsite:includenamespace=true:cleannamesofasynccontinuations=false}' /></targets>
<rules>
<logger name='*' levels='Debug' writeTo='debug' />
</rules>
</nlog>").LogFactory;

Task.Run(async () =>
{
await AMinimalAsyncMethod();
var logger = logFactory.GetCurrentClassLogger();
logger.Debug("dude");
}).Wait();

logFactory.AssertDebugLastMessageContains("NLog.UnitTests.LayoutRenderers.CallSiteTests");
logFactory.AssertDebugLastMessageContains("MoveNext");
}

private class InnerClassAsyncMethod6
{
public virtual async Task AsyncMethod6a(LogFactory logFactory)
Expand Down

[8]ページ先頭

©2009-2025 Movatter.jp