如何在 splat ReactiveUI 中设置日志记录?
How to set up logging in splat ReactiveUI?
我需要在 reactui 中启用日志记录。我实现了 ILogger
接口:
public class Logger : Splat.ILogger
{
public LogLevel Level { get; private set; }
public Logger(LogLevel level)
{
Level = level;
}
public void Write([Localizable(false)] string message, LogLevel logLevel)
{
if (logLevel >= Level)
Serilog.Log.Error(message);
}
public void Write(Exception exception, [Localizable(false)] string message, LogLevel logLevel)
{
if (logLevel >= Level)
Serilog.Log.Error(exception, message);
}
public void Write([Localizable(false)] string message, [Localizable(false)] Type type, LogLevel logLevel)
{
if (logLevel >= Level)
Serilog.Log.Error(message);
}
public void Write(Exception exception, [Localizable(false)] string message, [Localizable(false)] Type type, LogLevel logLevel)
{
if (logLevel >= Level)
Serilog.Log.Error(exception, message);
}
}
并注册:
var logger = new Logging.Logger(LogLevel.Info) { };
Locator.CurrentMutable.RegisterConstant(logger, typeof(ILogger));
并尝试像这样使用它:
LogHost.Default.Error("TestTestTest");
this.WhenAnyValue(x => x.IsHierarchical).Log(this, "ClusterableDictionaryValueSelector IsHierarchical exception")
.BindTo(this, x => x.ViewModel.IsHierarchical).DisposeWith(disposables);
但是我找不到日志文件。当我调用 LogHost.Default
时,没有调用任何方法。怎么了?
我们有一个为 Splat 制作的预制 Serilog 记录器。
您应该可以使用
注册它
using Splat.Serilog;
// Then in your service locator initialisation
locator.CurrentMutable.UseSerilogWithWrappingFullLogger();
有关详细信息,请参阅 https://github.com/reactiveui/splat#serilog。
那么您只需按正常方式注册记录器即可。
Splat Serilog 还支持开箱即用的语义日志记录,而 ILogger
会删除该信息。
我需要在 reactui 中启用日志记录。我实现了 ILogger
接口:
public class Logger : Splat.ILogger
{
public LogLevel Level { get; private set; }
public Logger(LogLevel level)
{
Level = level;
}
public void Write([Localizable(false)] string message, LogLevel logLevel)
{
if (logLevel >= Level)
Serilog.Log.Error(message);
}
public void Write(Exception exception, [Localizable(false)] string message, LogLevel logLevel)
{
if (logLevel >= Level)
Serilog.Log.Error(exception, message);
}
public void Write([Localizable(false)] string message, [Localizable(false)] Type type, LogLevel logLevel)
{
if (logLevel >= Level)
Serilog.Log.Error(message);
}
public void Write(Exception exception, [Localizable(false)] string message, [Localizable(false)] Type type, LogLevel logLevel)
{
if (logLevel >= Level)
Serilog.Log.Error(exception, message);
}
}
并注册:
var logger = new Logging.Logger(LogLevel.Info) { };
Locator.CurrentMutable.RegisterConstant(logger, typeof(ILogger));
并尝试像这样使用它:
LogHost.Default.Error("TestTestTest");
this.WhenAnyValue(x => x.IsHierarchical).Log(this, "ClusterableDictionaryValueSelector IsHierarchical exception")
.BindTo(this, x => x.ViewModel.IsHierarchical).DisposeWith(disposables);
但是我找不到日志文件。当我调用 LogHost.Default
时,没有调用任何方法。怎么了?
我们有一个为 Splat 制作的预制 Serilog 记录器。
您应该可以使用
注册它using Splat.Serilog;
// Then in your service locator initialisation
locator.CurrentMutable.UseSerilogWithWrappingFullLogger();
有关详细信息,请参阅 https://github.com/reactiveui/splat#serilog。
那么您只需按正常方式注册记录器即可。
Splat Serilog 还支持开箱即用的语义日志记录,而 ILogger
会删除该信息。