private void RotateLog() { logWriter.Close(); string archivingFile = archivingDirectory + "\\" + GetTimeStamp() + "-" + Path.GetFileName(fName); while (File.Exists(archivingFile) || File.Exists(archivingFile + ".zip")) { archivingFile += ".1"; } File.Move(fName, archivingFile); logWriter = new StreamWriter(fName, true); SafeThread worker = new SafeThread(delegate() { //compress the file CompressFile(archivingFile); //if we are syncing, start that on a separate thread if (synchronizer != null) { synchronizer.Sync(); } }, "post-log-rotation-work", this ); worker.Start(); }
/// <summary> /// This function will throw an exception if the log is non-rotating and if the container name does meet the following constraints: /// 1. Container names must start with a letter or number, and can contain only letters, numbers, and the dash (-) character. /// 2. Every dash (-) character must be immediately preceded and followed by a letter or number; consecutive dashes are not permitted in container names. /// 3. All letters in a container name must be lowercase. /// 4. Container names must be from 3 through 63 characters long /// </summary> /// <param name="accountName"></param> /// <param name="accountKey"></param> /// <param name="containerName"></param> public void InitSyncing(string accountName, string accountKey, string containerName) { if (!IsRotatingLog) { throw new Exception("Cannot sync a non-rotating log"); } //the code below could throw an exception if containerName does not meet the restrictions var locationInfo = new Bolt.DataStore.LocationInfo(accountName, accountKey, Bolt.DataStore.SynchronizerType.Azure); try { synchronizer = Bolt.DataStore.SyncFactory.Instance.CreateLogSynchronizer(locationInfo, containerName); synchronizer.SetLocalSource(archivingDirectory); //lets sync for starters, in case there are leftover logs from last time SafeThread worker = new SafeThread(delegate() { synchronizer.Sync(); }, "init log syncing", this); worker.Start(); } catch (System.FormatException ex1) { Log("ERROR: Could not start log syncing. The Azure account key may be wrong \n {0}", ex1.ToString()); } catch (System.Runtime.InteropServices.COMException ex2) { Log("ERROR: Could not start log syncing. It appears that the Sync Framework v2.1 x86 version is not installed. Make sure that no other version is present. \n {0}", ex2.ToString()); } catch (Microsoft.WindowsAzure.StorageClient.StorageServerException ex3) { Log("ERROR: Could not start log syncing. The Azure account name may be wrong.\n {0}", ex3.ToString()); } catch (Microsoft.WindowsAzure.StorageClient.StorageClientException ex3) { Log("ERROR: Could not start log syncing. The Azure account key may be wrong.\n {0}", ex3.ToString()); } catch (Exception ex3) { Log("Got unknown exception while starting log syncing.\n {0}", ex3.ToString()); } }
/// <summary> /// This function will throw an exception if the log is non-rotating and if the container name does meet the following constraints: /// 1. Container names must start with a letter or number, and can contain only letters, numbers, and the dash (-) character. /// 2. Every dash (-) character must be immediately preceded and followed by a letter or number; consecutive dashes are not permitted in container names. /// 3. All letters in a container name must be lowercase. /// 4. Container names must be from 3 through 63 characters long /// </summary> /// <param name="accountName"></param> /// <param name="accountKey"></param> /// <param name="containerName"></param> public void InitSyncing(string accountName, string accountKey, string containerName) { if (!IsRotatingLog) throw new Exception("Cannot sync a non-rotating log"); //the code below could throw an exception if containerName does not meet the restrictions var locationInfo = new Bolt.DataStore.LocationInfo(accountName, accountKey, Bolt.DataStore.SynchronizerType.Azure); try { synchronizer = Bolt.DataStore.SyncFactory.Instance.CreateLogSynchronizer(locationInfo, containerName); synchronizer.SetLocalSource(archivingDirectory); //lets sync for starters, in case there are leftover logs from last time SafeThread worker = new SafeThread(delegate() { synchronizer.Sync(); }, "init log syncing", this); worker.Start(); } catch (System.FormatException ex1) { Log("ERROR: Could not start log syncing. The Azure account key may be wrong \n {0}", ex1.ToString()); } catch (System.Runtime.InteropServices.COMException ex2) { Log("ERROR: Could not start log syncing. It appears that the Sync Framework v2.1 x86 version is not installed. Make sure that no other version is present. \n {0}", ex2.ToString()); } catch (Microsoft.WindowsAzure.StorageClient.StorageServerException ex3) { Log("ERROR: Could not start log syncing. The Azure account name may be wrong.\n {0}", ex3.ToString()); } catch (Microsoft.WindowsAzure.StorageClient.StorageClientException ex3) { Log("ERROR: Could not start log syncing. The Azure account key may be wrong.\n {0}", ex3.ToString()); } catch (Exception ex3) { Log("Got unknown exception while starting log syncing.\n {0}", ex3.ToString()); } }