似乎我需要为日志进行配置。我可以添加作业&在/hangfire页面中看到它们,但是如果禁用app.UseHangfireServer(),它们就不会启动。
因为它是一个简单的基于文件夹的网站,所以我已经从运行示例Hangfire项目将必要的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发布于 2015-12-13 19:00:54
我有两个创业点:
[assembly: OwinStartup(typeof(MyWebApplication.Startup))]和
[ApplicationStartup]删除ApplicationStartup并将与Hangfire相关的代码移到其他地方,解决了问题。
发布于 2015-12-08 20:17:33
我个人使用Elmah (在较新的版本中Hangfire会自动检测到这一点)。
但是,如果您想关闭它,将日志提供程序设置为null应该可以做到这一点(您可以将其放在应用程序的启动方法中,这取决于您执行启动的机制)。
LogProvider.SetCurrentLogProvider(null);发布于 2015-12-08 23:20:33
您有在解决方案中应用任何记录器库吗?正如Hangfire文档所述:
从Hangfire 1.3.0开始,如果您的应用程序已经通过反射使用了以下库之一,则不需要做任何操作(这样Hangfire本身就不依赖于其中的任何一个库)。通过检查是否存在相应的类型,将自动选择日志实现,顺序如下。 如果您想要记录Hangfire事件并且没有安装日志库,请选择上面的一个并参考它的文档。
因此,据我所知,您需要上面列出的一些日志库。
https://stackoverflow.com/questions/34164962
复制相似问题