Postsharp does not log on trace level

半城伤御伤魂 提交于 2020-01-14 14:33:09

问题


I like to log some Postsharp messages on trace level. Unfortunately logs to this level print no output. All other levels are working. Same behavior with console or NLog backend or when I log from an other class.

How can I enable the trace level?

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:


LogLevel.Trace is the lowest logging level in the PostSharp Diagnostics library. By default, the verbosity of a logging back-end is set to LogLevel.Debug and all trace messages are ignored as a result. You can customize the verbosity of a logging back-end as shown in the example below:

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


来源:https://stackoverflow.com/questions/55480326/postsharp-does-not-log-on-trace-level

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!