r2d2
r2d2

Reputation: 637

Postsharp does not log on trace level

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_*" )]

Upvotes: 3

Views: 241

Answers (1)

AlexD
AlexD

Reputation: 5101

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 );

Upvotes: 3

Related Questions