我喜欢在跟踪级别上记录一些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 );