0

这是调度输出任务的主要过程

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

和工作类别

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()

something.dll 中发生了“System.TypeInitializationException”类型的异常,但未在用户代码中处理

附加信息:“Quartz.Impl.StdSchedulerFactory”的类型初始值设定项引发了异常。

输出中的异常消息(显示在 Visual Studio 的底部):

Common.Logging.dll 中出现“Common.Logging.ConfigurationException”类型的第一次机会异常 something.dll 中出现“System.TypeInitializationException”类型的第一次机会异常

我该如何解决异常?

以及代码中可能导致错误/异常的任何其他部分?

我为此苦苦挣扎了很长时间,并搜索了很多解决方案,但没有一个能真正帮助我(或者只是我不知道如何修改以适应我的代码),因为我真的缺乏关于任务调度的知识和配置设置。

4

1 回答 1

1

Quartz 仅依赖于一个名为 Common.Logging 的第三方库(它包含允许您使用最适合您的日志记录提供程序的日志记录抽象)。您需要在应用程序二进制文件旁边有 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>
于 2019-05-24T22:27:40.983 回答