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".read.log""/>
<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, 오른쪽 단추, 속성, 출력 디렉터리로 복사, 선택: 항상 복사
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
C#Task를 사용하여 비동기식 작업을 수행하는 방법라인이 완성된 후에 이 라인을 다시 시작할 수 없습니다.반대로 조인(Join)만 결합할 수 있습니다 (프로세스가 현재 라인을 막습니다). 임무는 조합할 수 있는 것이다. 연장을 사용하여 그것들을 한데 연결시키는 것이...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.