Simple NCron service:
class Program
{
static void Main(string[] args)
{
var schedService = new SchedulingService();
schedService.At("* * * * *").Run<MyTask>(); // run every minute
schedService.Start();
Console.ReadLine();
}
}
public class MyTask : NCron.ICronJob
{
public void Execute()
{
Console.WriteLine("executing");
}
public void Initialize(NCron.CronContext context)
{
}
public void Dispose()
{
}
}
Upon reaching the first minute but before executing MyTask, NCron seems to want to write to the Windows Event Log, and fails with
Unhandled Exception: System.Security.SecurityException: The source was not found, but some or all event logs could not be searched. To create the source, you need permission to read all event logs to make sure that the new source name is unique. Inaccessible logs: Security.
at System.Diagnostics.EventLogInternal.FindSourceRegistration(String source, String machineName, Boolean readOnly, Boolean wantToCreate)
at System.Diagnostics.EventLogInternal.SourceExists(String source, String machineName, Boolean wantToCreate)
at System.Diagnostics.EventLogInternal.VerifyAndCreateSource(String sourceName, String currentMachineName)
at System.Diagnostics.EventLogInternal.WriteEntry(String message, EventLogEntryType type, Int32 eventID, Int16 category, Byte[] rawData)
at System.Diagnostics.EventLog.WriteEntry(String message, EventLogEntryType type)
at NCron.ExceptionHelper.LogUnhandledException(Object exception)
at NCron.Service.SchedulingService.WaitCallbackHandler(Object data)
at System.Threading.QueueUserWorkItemCallback.WaitCallback_Context(Object state)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean ignoreSyncCtx)
at System.Threading.QueueUserWorkItemCallback.System.Threading.IThreadPoolWorkItem.ExecuteWorkItem()
at System.Threading.ThreadPoolWorkQueue.Dispatch()
at System.Threading._ThreadPoolWaitCallback.PerformWaitCallback()`
What and why is NCron writing to the Event Log? This is the default behavior, so anyone using NCron must have dealt with this, I suppose, but I can't find any documentation or question/answers about the issue. I tried setting schedService.LogFactory = null;
, which doesn't change anything.
Short of creating a custom log factory (which I don't want to do), or fiddling with the registry (which I really don't want to do, and sometimes can't on production machines), how can I fix this?