gpt4 book ai didi

c# - Postsharp 不登录跟踪级别

转载 作者:行者123 更新时间:2023-11-30 22:55:11 28 4
gpt4 key购买 nike

我喜欢在跟踪级别上记录一些 Postsharp 消息。不幸的是,记录到这个级别没有输出。所有其他级别都在工作。与控制台或 NLog 后端或当我从其他类登录时的行为相同。

如何启用跟踪级别?

App.xaml.cs:

[Log(AttributeExclude = true)]
public partial class App
{
private static readonly LogSource LogSource = LogSources.Default.ForCurrentType().WithLevels(LogLevel.Trace, LogLevel.Error);

protected override void OnStartup(StartupEventArgs e)
{
LoggingServices.DefaultBackend = new PostSharp.Patterns.Diagnostics.Backends.Console.ConsoleLoggingBackend();
LogSource.Debug.Write(Formatted("Debug")); // prints "Debug"
LogSource.Trace.Write(Formatted("Trace")); // prints nothing
LogSource.Default.Write(Formatted("Default")); // prints nothing
LogSource.Trace.IsEnabled // is false
..

GlobalAspect.cs

using PostSharp.Patterns.Diagnostics;
using PostSharp.Extensibility;

[assembly: Log(AttributePriority = 1, AttributeTargetMemberAttributes = MulticastAttributes.Protected | MulticastAttributes.Internal | MulticastAttributes.Public)]
[assembly: Log(AttributePriority = 2, AttributeExclude = true, AttributeTargetMembers = "get_*" )]

最佳答案

LogLevel.Trace 是 PostSharp 诊断库中的最低日志记录级别。默认情况下,日志记录后端的详细程度设置为 LogLevel.Debug,因此所有跟踪消息都将被忽略。您可以自定义日志记录后端的详细程度,如下例所示:

LoggingServices.DefaultBackend.DefaultVerbosity.SetMinimalLevel( LogLevel.Trace );

关于c# - Postsharp 不登录跟踪级别,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55480326/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com