好像我需要配置日志记录。我可以添加工作和在/ hangfire页面中看到它们但是如果我禁用app.UseHangfireServer()它们将不会触发。
由于这是一个简单的基于文件夹的网站,我已经从运行示例Hangfire MVC项目中将必要的dll复制到我的bin文件夹。如果需要,我该如何配置记录器?
Error location:
Line 17: {
Line 18: app.UseHangfireServer();
Line 19: app.UseHangfireDashboard();
Line 20:
Source File: f:\hangfire\App_Code\Startup.cs Line: 18
堆栈追踪:
[ConfigurationErrorsException: The configuration section for Logging cannot be found in the configuration source.]
Microsoft.Practices.EnterpriseLibrary.Logging.LogWriterStructureHolderCustomFactory.ValidateLoggingSettings(LoggingSettings loggingSettings) +64
Microsoft.Practices.EnterpriseLibrary.Logging.LogWriterStructureHolderCustomFactory.CreateObject(IBuilderContext context, String name, IConfigurationSource configurationSource, ConfigurationReflectionCache reflectionCache) +49
Microsoft.Practices.EnterpriseLibrary.Logging.LogWriterCustomFactory.CreateObject(IBuilderContext context, String name, IConfigurationSource configurationSource, ConfigurationReflectionCache reflectionCache) +66
Microsoft.Practices.EnterpriseLibrary.Common.Configuration.ObjectBuilder.ConfiguredObjectStrategy.BuildUp(IBuilderContext context, Type t, Object existing, String id) +83
Microsoft.Practices.ObjectBuilder.BuilderStrategy.BuildUp(IBuilderContext context, Type typeToBuild, Object existing, String idToBuild) +59
Microsoft.Practices.ObjectBuilder.SingletonStrategy.BuildUp(IBuilderContext context, Type typeToBuild, Object existing, String idToBuild) +169
Microsoft.Practices.ObjectBuilder.BuilderStrategy.BuildUp(IBuilderContext context, Type typeToBuild, Object existing, String idToBuild) +59
Microsoft.Practices.EnterpriseLibrary.Common.Configuration.ObjectBuilder.ConfigurationNameMappingStrategy.BuildUp(IBuilderContext context, Type t, Object existing, String id) +102
Microsoft.Practices.ObjectBuilder.BuilderBase`1.DoBuildUp(IReadWriteLocator locator, Type typeToBuild, String idToBuild, Object existing, PolicyList[] transientPolicies) +217
Microsoft.Practices.ObjectBuilder.BuilderBase`1.BuildUp(IReadWriteLocator locator, Type typeToBuild, String idToBuild, Object existing, PolicyList[] transientPolicies) +127
Microsoft.Practices.ObjectBuilder.BuilderBase`1.BuildUp(IReadWriteLocator locator, String idToBuild, Object existing, PolicyList[] transientPolicies) +87
Microsoft.Practices.EnterpriseLibrary.Common.Configuration.ObjectBuilder.EnterpriseLibraryFactory.BuildUp(IReadWriteLocator locator, IConfigurationSource configurationSource) +135
Microsoft.Practices.EnterpriseLibrary.Common.Configuration.ObjectBuilder.EnterpriseLibraryFactory.BuildUp(IConfigurationSource configurationSource) +53
Microsoft.Practices.EnterpriseLibrary.Logging.LogWriterFactory.Create() +29
Microsoft.Practices.EnterpriseLibrary.Logging.Logger.get_Writer() +106
lambda_method(Closure , String , TraceEventType ) +252
Hangfire.Logging.LogProviders.EntLibLogger.Log(LogLevel logLevel, Func`1 messageFunc, Exception exception) +60
Hangfire.Logging.LoggerExecutionWrapper.Log(LogLevel logLevel, Func`1 messageFunc, Exception exception) +87
Hangfire.Logging.LogExtensions.IsInfoEnabled(ILog logger) +42
Hangfire.Logging.LogExtensions.Info(ILog logger, String message) +27
Hangfire.BackgroundJobServer..ctor(BackgroundJobServerOptions options, JobStorage storage, IEnumerable`1 additionalProcesses) +236
Hangfire.AppBuilderExtensions.UseHangfireServer(IAppBuilder builder, JobStorage storage, BackgroundJobServerOptions options, IBackgroundProcess[] additionalProcesses) +90
Hangfire.AppBuilderExtensions.UseHangfireServer(IAppBuilder builder, BackgroundJobServerOptions options, JobStorage storage) +42
Hangfire.AppBuilderExtensions.UseHangfireServer(IAppBuilder builder, BackgroundJobServerOptions options) +35
Hangfire.AppBuilderExtensions.UseHangfireServer(IAppBuilder builder) +46
MyWebApplication.Startup.Configuration(IAppBuilder app) in f:\hangfire\App_Code\Startup.cs:18
答案 0 :(得分:0)
我个人使用Elmah(Hangfire会在较新版本中自动检测到)。
但是如果要关闭它,将日志提供程序设置为null应该可以解决问题(您可以将其放在应用程序的启动方法中,这将根据您使用的机制而有所不同执行启动)
LogProvider.SetCurrentLogProvider(null);
答案 1 :(得分:0)
您的解决方案是否应用了任何记录器库?正如Hangfire文档所说:
从Hangfire 1.3.0开始,如果是,则无需执行任何操作 您的应用程序已经使用以下库之一 反思(以便Hangfire本身不依赖于任何一个 他们)。通过检查自动选择记录实现 按以下顺序存在相应的类型。
Serilog NLOG log4net的 EntLib 记录放大镜 ELMAH 如果你想记录 Hangfire事件并没有安装日志库,请选择 以上之一并参考其文档
据我了解你需要一些上面列出的日志库。
答案 2 :(得分:0)
我有两个创业点:
[assembly: OwinStartup(typeof(MyWebApplication.Startup))]
和
[ApplicationStartup]
删除[ApplicationStartup]并将Hangfire相关代码移动到其他位置以解决问题。
答案 3 :(得分:0)
您必须添加日志提供程序。作为示例,您可以像这样添加一个构建提供程序:
LogProvider.SetCurrentLogProvider(new ColouredConsoleLogProvider());
它应该解决错误。