This project is read-only.

Releasing File Lock

Feb 15, 2013 at 10:18 PM
Hello everyone,

I have a program which uses SLF for logging. This program runs 24/7 and I would like to upload the log files to a remote server every night for later review.

My question is, how do I release the file lock for the log without closing the program?

I was hoping to suspend logging, upload the logs, either delete the log file or erase the contents, and then resume logging.
ILogger logger = LoggerService.GetLogger(typeof(TaskScheduler).FullName);

// Other initialization here

foreach (var task in managedTasks.OrderBy(t => t.Priority))
    if (task.NextRunTime <= DateTime.Now)
        dataManager.CurrentStatus = AppStatus.Running;
        if (task.Name == "Log Sender")
             logger = null;

        // Run the task

        if (task.Name == "Log Sender")
            logger = LoggerService.GetLogger(typeof(TaskScheduler).FullName);

        dataManager.CurrentStatus = AppStatus.Idle;
Currently, when I do this, I'm still getting an IOException because the file is still locked by the Task Scheduler.

Any ideas are appreciated.