【发布时间】:2019-11-25 07:09:52
【问题描述】:
我需要启用响应式登录。我实现了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 时,没有调用任何方法。怎么了?
【问题讨论】:
-
为什么不使用我们为 ReactiveUI 制作的预制 Serilog 记录器? github.com/reactiveui/splat#serilog
标签: c# .net-core reactiveui splat