/// <summary>
    /// This makes sure that the writer exists to be written to.
    /// </summary>
    private void ensureWriter()
    {
        //Resolve file name given. relative paths (if present) are resolved to full paths.
        // Also allows for paths like this: initializeData="~/Logs/{ApplicationName}_{DateTime:yyyy-MM-dd}.log"
        var logFileFullPath = ServerPathUtility.ResolvePhysicalPath(fileName);
        var writer          = base.Writer;

        if (writer == null && createWriter(logFileFullPath))
        {
            writer = base.Writer;
        }
        if (!File.Exists(logFileFullPath))
        {
            if (writer != null)
            {
                try {
                    writer.Flush();
                    writer.Close();
                    writer.Dispose();
                } catch (ObjectDisposedException) { }
            }
            createWriter(logFileFullPath);
        }
        //Custom code to package the previous log file(s) into a zip file.
        if (AddToArchive)
        {
            TextFileArchiveHelper.Archive(logFileFullPath);
        }
    }
 bool createWriter(string logFileFullPath)
 {
     try {
         logFileFullPath = ServerPathUtility.ResolveOrCreatePath(logFileFullPath);
         var writer = new StreamWriter(logFileFullPath, true);
         base.Writer = writer;
         return(true);
     } catch (IOException) {
         //locked as already in use
         return(false);
     } catch (UnauthorizedAccessException) {
         //ERROR_ACCESS_DENIED, mostly ACL issues
         return(false);
     }
 }