C#Quartz 정시 퀘스트, 직접 납품

20482 단어 c#
프로젝트 데모는 내 자원에 다운로드할 수 있고 직접 실행할 수 있습니다. 안 돼요. 저를 찾아오세요.

1. app.config


<configuration>
  <configSections>
    <section name="quartz" type="System.Configuration.NameValueSectionHandler, System, Version=1.0.5000.0,Culture=neutral, PublicKeyToken=b77a5c561934e089"/>
    <sectionGroup name="common">
      <section name="logging" type="Common.Logging.ConfigurationSectionHandler, Common.Logging"/>
    sectionGroup>
  configSections>

  <common>
    <logging>
      <factoryAdapter type="Common.Logging.Simple.ConsoleOutLoggerFactoryAdapter, Common.Logging">
        <arg key="showLogName" value="true"/>
        <arg key="showDataTime" value="true"/>
        <arg key="level" value="DEBUG"/>
        <arg key="dateTimeFormat" value="HH:mm:ss:fff"/>
      factoryAdapter>
    logging>
  common>
  <startup>
    <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/>
  startup>
configuration>

2. log4net.config


<configuration>
  <configSections>
    <section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler, log4net"/>
  configSections>

  <log4net>
    <appender name="RollingLogFileAppender" type="log4net.Appender.RollingFileAppender">
      
      <param name= "File" value= "D:\App_Log\servicelog\"/>
      
      <param name= "AppendToFile" value= "true"/>
      
      <param name= "MaxSizeRollBackups" value= "10"/>
      
      <param name= "StaticLogFileName" value= "false"/>
      
      <param name= "DatePattern" value= "yyyy-MM-dd&quot;.read.log&quot;"/>
      
      <param name= "RollingStyle" value= "Date"/>
      <layout type="log4net.Layout.PatternLayout">
        <param name="ConversionPattern" value="%d [%t] %-5p %c - %m%n %loggername" />
      layout>
    appender>

    
    <appender name="ColoredConsoleAppender" type="log4net.Appender.ColoredConsoleAppender">
      <mapping>
        <level value="DEBUG" />
        <foreColor value="Red, HighIntensity" />
      mapping>
      <mapping>
        <level value="DEBUG" />
        <foreColor value="Green" />
      mapping>
      <layout type="log4net.Layout.PatternLayout">
        <conversionPattern value="%n%date{HH:mm:ss,fff} [%-5level] %m" />
      layout>

      <filter type="log4net.Filter.LevelRangeFilter">
        <param name="LevelMin" value="Info" />
        <param name="LevelMax" value="Fatal" />
      filter>
    appender>

    <root>
      
      <level value="all" />
      <appender-ref ref="ColoredConsoleAppender"/>
      <appender-ref ref="RollingLogFileAppender"/>
    root>
  log4net>
configuration>

3. quartz.config

# You can configure your scheduler in either  configuration section  
# or in quartz properties file  
# Configuration section has precedence  

quartz.scheduler.instanceName = ServerScheduler  

# configure thread pool info  
quartz.threadPool.type = Quartz.Simpl.SimpleThreadPool, Quartz  
quartz.threadPool.threadCount = 10  
quartz.threadPool.threadPriority = Normal  

# job initialization plugin handles our xml reading, without it defaults are used  
quartz.plugin.xml.type = Quartz.Plugin.Xml.XMLSchedulingDataProcessorPlugin, Quartz
quartz.plugin.xml.fileNames = ~/quartz_jobs.xml  

# export this server to remoting context  
quartz.scheduler.exporter.type = Quartz.Simpl.RemotingSchedulerExporter, Quartz  
quartz.scheduler.exporter.port = 555  
quartz.scheduler.exporter.bindName = QuartzScheduler  
quartz.scheduler.exporter.channelType = tcp  
quartz.scheduler.exporter.channelName = httpQuartz  

4. quartz_jobs.xml

<job-scheduling-data xmlns="http://quartznet.sourceforge.net/JobSchedulingData" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="2.0">

  <processing-directives>
    <overwrite-existing-data>trueoverwrite-existing-data>
  processing-directives>

  <schedule>

    <job>
      <name>sampleJobname>
      <group>sampleGroupgroup>
      <description>Sample job for Quartz Serverdescription>
      <job-type>QuartzDemo.TestJob,QuartzDemojob-type>
      <durable>truedurable>
      <recover>falserecover>
    job>

    <trigger>
      <simple>
        <name>sampleSimpleTriggername>
        <group>sampleSimpleGroupgroup>
        <description>Simple trigger to simply fire sample jobdescription>
        <job-name>sampleJobjob-name>
        <job-group>sampleGroupjob-group>
        <misfire-instruction>SmartPolicymisfire-instruction>
        <repeat-count>-1repeat-count>
        <repeat-interval>1000repeat-interval>
      simple>
    trigger>
  schedule>
job-scheduling-data>

5. TestJob.cs

using Common.Logging;
using Quartz;

namespace QuartzDemo
{
    public class TestJob : IJob
    {
        #region IJob  
        private readonly ILog log = LogManager.GetLogger(typeof(TestJob));

        public void Execute(IJobExecutionContext context)
        {
            log.Info(" ");
        }
        #endregion
    }
}

6. Program.cs

using System;
using Common.Logging;
using Quartz;
using Quartz.Impl;

namespace QuartzDemo
{
    public class Program
    {
        private static ILog log = Common.Logging.LogManager.GetLogger(typeof(TestJob));
        static void Main(string[] args)
        {
            log.Debug("debug");
            log.Info("info");
            log.Error("error");

            ISchedulerFactory schedulerFactory = new StdSchedulerFactory();
            IScheduler scheduler = schedulerFactory.GetScheduler();
            scheduler.Start();
            Console.ReadKey();
        }
    }
}

주의: 앱.config,log4net.config,quartz.config,quartz_jobs.xml, 오른쪽 단추, 속성, 출력 디렉터리로 복사, 선택: 항상 복사

좋은 웹페이지 즐겨찾기