问题描述
我的解决方案有一个主记录器,定义为
I have a main logger for my solution which is defined as
Log.Logger = new LoggerConfiguration()
.MinimumLevel.Verbose()
.WriteTo.LiterateConsole(LogEventLevel.Verbose)
.WriteTo.RollingFile($"{appLogDir}{Path.DirectorySeparatorChar}logs{Path.DirectorySeparatorChar}V-RPi-{{Date}}.log")
.WriteTo.RollingFile($"{appLogDir}{Path.DirectorySeparatorChar}logs-warnings{Path.DirectorySeparatorChar}V-RPi-{{Date}}.log", LogEventLevel.Warning)
.WriteTo.File($"{appLogDir}{Path.DirectorySeparatorChar}recent-log.log", fileSizeLimitBytes: 134217728, restrictedToMinimumLevel: LogEventLevel.Verbose)
.CreateLogger();
我想创建两个单独的记录器来记录两个类实例中的内容.我已将它们定义如下.它位于与主项目不同的程序集中.
I want to create two separate loggers to log things in two class instances. I have defined them as below. This is located in a separate assembly from the main project.
private ILogger comRespLog;
public **constructor**(string name)
{
comRespLog = new LoggerConfiguration()
.MinimumLevel.Verbose()
.WriteTo.RollingFile($"{appLogDir}{Path.DirectorySeparatorChar}logs-CommandResponse-{Name}{Path.DirectorySeparatorChar}V-RPi-{{Date}}.log")
.CreateLogger();
}
我没有收到任何构建错误,但我在运行时收到了这个错误.
I receive no build errors but I receive this at run time.
找不到方法:'Serilog.LoggerConfigurationSerilog.RollingFileLoggerConfigurationExtensions.RollingFile(Serilog.Configuration.LoggerSinkConfiguration,System.String, Serilog.Events.LogEventLevel, System.String,System.IFormatProvider, System.Nullable1,System.Nullable
1, Serilog.Core.LoggingLevelSwitch, Boolean,布尔值,System.Nullable`1)'."}
推荐答案
事实证明,我在主程序集中引用了比在子程序集中更旧的 nuget 包.更新它们使它们匹配后,问题就消失了.
Turns out I was referencing an older nuget package in my Main Assembly than I was in the sub assembly. After updating them so they match the problem went away.
这篇关于找不到方法:'Serilog.LoggerConfiguration的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!