2015-12-08 176 views
0

看來我需要配置日誌記錄。我可以增加就業機會&看到他們在/遲髮型頁,但如果我停用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

我有兩個啓動點:

[assembly: OwinStartup(typeof(MyWebApplication.Startup))] 

[ApplicationStartup] 

刪除[ApplicationStartup]和movind的遲髮型相關的代碼放到固定的問題的其他地方。

0

我個人使用ELMAH(其中遲髮型在新版本自動檢測)。

但如果你想關閉它,設置日誌提供空應該做的伎倆(你最好把這個在​​您的應用程序的啓動方法,這將是不同的,這取決於你是什麼樣的機制通過執行啓動時)

LogProvider.SetCurrentLogProvider(null); 

來源:https://discuss.hangfire.io/t/turn-off-logging/1150

+0

它並沒有幫助。該代碼已執行,我收到了相同的配置未找到錯誤。 –

+0

你使用的是什麼版本的hangfire,你的初始化代碼是什麼樣的?我只是試圖在一個全新的項目中重新創建你的問題(剛剛安裝了hangfire,啓動了後臺服務器,沒有任何配置用於日誌記錄),它運行時沒有任何異常。 – MutantNinjaCodeMonkey

0

你有適用您的解決方案的任何記錄庫?作爲遲髮型文件說:

從遲髮型1.3.0開始,你不需要做任何事情,如果你 應用程序已經使用了以下庫之一,通過 反射(這樣遲髮型本身不依賴於他們中的任何一個)。日誌實現是通過檢查相應 類型的在以下所示的順序中存在自動選擇。

Serilog NLOG log4net的 EntLib 登錄放大鏡 ELMAH 如果你想記錄 遲髮型事件並沒有安裝日誌庫,請選擇上面的 之一,並指其文檔

所以據我所知你需要一些上面列出的日誌庫。

0

您必須添加日誌提供。作爲示例,您可以添加內置提供程序,如下所示:

LogProvider.SetCurrentLogProvider(new ColouredConsoleLogProvider());

它應該解決錯誤。