无法按 Quartz.NET 安排任务
Unable to schedule tasks by Quartz.NET
这里是调度输出任务的主要流程
Public Sub ScheduleOutput()
Dim sf As ISchedulerFactory = New StdSchedulerFactory()
Dim scheduler As IScheduler = sf.GetScheduler()
scheduler.Start()
Dim job As IJobDetail = JobBuilder.Create(Of OutputJob)().
WithIdentity("output", "output").Build()
Dim trigger As ITrigger = TriggerBuilder.Create().
WithIdentity("trigger", "trigger").ForJob("output").
WithSchedule(CronScheduleBuilder.DailyAtHourAndMinute(setHour.Text, setMinute.Text)).
Build()
MsgBox("end")
End Sub
和工作 class
Public Class OutputJob
Implements IJob
Public Sub Execute(context As IJobExecutionContext) Implements IJob.Execute
Output()
End Sub
Public Sub Output()
Dim b = Convert.FromBase64String(HttpContext.Current.Request.Form("encodedhtml"))
Dim html = System.Text.Encoding.UTF8.GetString(b)
HttpContext.Current.Response.Clear()
HttpContext.Current.Response.ContentType = "text/html"
HttpContext.Current.Response.AddHeader("Content-Disposition", "attachment;filename=""Dashboard.html""")
HttpContext.Current.Response.Write(html)
HttpContext.Current.Response.End()
End Sub
End Class
Web.config 文件
<configuration>
<configSections>
<sectionGroup name="common">
<section name="logging" type="Common.Logging.ConfigurationSectionHandler, Common.Logging" />
</sectionGroup>
<section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler, log4net"/>
</configSections>
<common>
<logging>
<factoryAdapter type="Common.Logging.Log4Net.Log4NetLoggerFactoryAdapter, Common.Logging.Log4Net1213">
<arg key="configType" value="INLINE"/>
<arg key="configFile" value="~/log4net.config"/>
<arg key="level" value="INFO" />
</factoryAdapter>
</logging>
</common>
<log4net>
<appender name="EventLogAppender" type="log4net.Appender.EventLogAppender">
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%d [%t] %-5p %l - %m%n" />
</layout>
</appender>
<root>
<level value="INFO" />
<appender-ref ref="EventLogAppender" />
</root>
</log4net>
</configuration>
当我尝试运行代码时,Dim sf As ISchedulerFactory = New StdSchedulerFactory()
出现异常
An exception of type 'System.TypeInitializationException' occurred in something.dll but was not handled in user code
Additional information: The type initializer for 'Quartz.Impl.StdSchedulerFactory' threw an exception.
输出中的异常消息(显示在 Visual Studio 的底部):
A first chance exception of type
'Common.Logging.ConfigurationException' occurred in Common.Logging.dll
A first chance exception of type 'System.TypeInitializationException'
occurred in something.dll
如何修复异常?
以及代码中可能导致 errors/exceptions 的任何其他部分?
我为此苦苦挣扎了很长时间,并搜索了很多解决方案,但其中 none 实际上可以帮助我(或者只是我不知道如何修改以适合我的代码) 因为我实在是缺乏任务调度和配置设置方面的知识。
Quartz 仅依赖于一个名为 Common.Logging 的 third-party 库(它包含允许您使用最适合您的日志记录提供程序的日志记录抽象)。您的应用程序二进制文件旁边需要 Quartz.dll、Commong.Logging.dll 和 Commong.Logging.Core.dll 才能成功 运行 Quartz.NET
并将 Common.Logging.Log4Net1213.dll 部分替换为:
<common>
<logging>
<factoryAdapter type="Common.Logging.Log4Net.Log4NetLoggerFactoryAdapter, Common.Logging.Log4Net1213">
<arg key="configType" value="INLINE"/>
<arg key="level" value="INFO" />
</factoryAdapter>
</logging>
</common>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="Common.Logging" publicKeyToken="af08829b84f0328e" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-3.3.1.0" newVersion="3.3.1.0" />
</dependentAssembly>
</assemblyBinding>
</runtime>
这里是调度输出任务的主要流程
Public Sub ScheduleOutput()
Dim sf As ISchedulerFactory = New StdSchedulerFactory()
Dim scheduler As IScheduler = sf.GetScheduler()
scheduler.Start()
Dim job As IJobDetail = JobBuilder.Create(Of OutputJob)().
WithIdentity("output", "output").Build()
Dim trigger As ITrigger = TriggerBuilder.Create().
WithIdentity("trigger", "trigger").ForJob("output").
WithSchedule(CronScheduleBuilder.DailyAtHourAndMinute(setHour.Text, setMinute.Text)).
Build()
MsgBox("end")
End Sub
和工作 class
Public Class OutputJob
Implements IJob
Public Sub Execute(context As IJobExecutionContext) Implements IJob.Execute
Output()
End Sub
Public Sub Output()
Dim b = Convert.FromBase64String(HttpContext.Current.Request.Form("encodedhtml"))
Dim html = System.Text.Encoding.UTF8.GetString(b)
HttpContext.Current.Response.Clear()
HttpContext.Current.Response.ContentType = "text/html"
HttpContext.Current.Response.AddHeader("Content-Disposition", "attachment;filename=""Dashboard.html""")
HttpContext.Current.Response.Write(html)
HttpContext.Current.Response.End()
End Sub
End Class
Web.config 文件
<configuration>
<configSections>
<sectionGroup name="common">
<section name="logging" type="Common.Logging.ConfigurationSectionHandler, Common.Logging" />
</sectionGroup>
<section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler, log4net"/>
</configSections>
<common>
<logging>
<factoryAdapter type="Common.Logging.Log4Net.Log4NetLoggerFactoryAdapter, Common.Logging.Log4Net1213">
<arg key="configType" value="INLINE"/>
<arg key="configFile" value="~/log4net.config"/>
<arg key="level" value="INFO" />
</factoryAdapter>
</logging>
</common>
<log4net>
<appender name="EventLogAppender" type="log4net.Appender.EventLogAppender">
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%d [%t] %-5p %l - %m%n" />
</layout>
</appender>
<root>
<level value="INFO" />
<appender-ref ref="EventLogAppender" />
</root>
</log4net>
</configuration>
当我尝试运行代码时,Dim sf As ISchedulerFactory = New StdSchedulerFactory()
An exception of type 'System.TypeInitializationException' occurred in something.dll but was not handled in user code
Additional information: The type initializer for 'Quartz.Impl.StdSchedulerFactory' threw an exception.
输出中的异常消息(显示在 Visual Studio 的底部):
A first chance exception of type 'Common.Logging.ConfigurationException' occurred in Common.Logging.dll A first chance exception of type 'System.TypeInitializationException' occurred in something.dll
如何修复异常?
以及代码中可能导致 errors/exceptions 的任何其他部分?
我为此苦苦挣扎了很长时间,并搜索了很多解决方案,但其中 none 实际上可以帮助我(或者只是我不知道如何修改以适合我的代码) 因为我实在是缺乏任务调度和配置设置方面的知识。
Quartz 仅依赖于一个名为 Common.Logging 的 third-party 库(它包含允许您使用最适合您的日志记录提供程序的日志记录抽象)。您的应用程序二进制文件旁边需要 Quartz.dll、Commong.Logging.dll 和 Commong.Logging.Core.dll 才能成功 运行 Quartz.NET
并将 Common.Logging.Log4Net1213.dll 部分替换为:
<common>
<logging>
<factoryAdapter type="Common.Logging.Log4Net.Log4NetLoggerFactoryAdapter, Common.Logging.Log4Net1213">
<arg key="configType" value="INLINE"/>
<arg key="level" value="INFO" />
</factoryAdapter>
</logging>
</common>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="Common.Logging" publicKeyToken="af08829b84f0328e" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-3.3.1.0" newVersion="3.3.1.0" />
</dependentAssembly>
</assemblyBinding>
</runtime>