Postsharp不登录跟踪级别

时间:2019-04-02 17:18:31

标签: c# postsharp

我喜欢在跟踪级别记录一些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_*" )]

1 个答案:

答案 0 :(得分:1)

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

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