private static void Initialize(ExDateTime serviceStartTime, string logFilePath, TimeSpan maxRetentionPeriond, ByteQuantifiedSize directorySizeQuota, ByteQuantifiedSize perFileSizeQuota, bool applyHourPrecision) { int registryInt; using (RegistryKey registryKey = Registry.LocalMachine.OpenSubKey("SYSTEM\\CurrentControlSet\\Services\\MSExchange Mserv\\Parameters")) { MservProtocolLog.Enabled = MservProtocolLog.GetRegistryBool(registryKey, "ProtocolLoggingEnabled", true); registryInt = MservProtocolLog.GetRegistryInt(registryKey, "LogBufferSize", 65536); } if (MservProtocolLog.registryWatcher == null) { MservProtocolLog.registryWatcher = new RegistryWatcher("SYSTEM\\CurrentControlSet\\Services\\MSExchange Mserv\\Parameters", false); } if (MservProtocolLog.timer == null) { MservProtocolLog.timer = new Timer(new TimerCallback(MservProtocolLog.UpdateConfigIfChanged), null, 0, 300000); } if (MservProtocolLog.Enabled) { MservProtocolLog.log = new Log(MservProtocolLog.logFilePrefix, new LogHeaderFormatter(MservProtocolLog.schema, LogHeaderCsvOption.CsvCompatible), "MservLogs"); MservProtocolLog.log.Configure(logFilePath, maxRetentionPeriond, (long)directorySizeQuota.ToBytes(), (long)perFileSizeQuota.ToBytes(), applyHourPrecision, registryInt, MservProtocolLog.defaultFlushInterval); AppDomain.CurrentDomain.ProcessExit += MservProtocolLog.CurrentDomain_ProcessExit; } MservProtocolLog.Initialized = true; }
private static void UpdateConfigIfChanged(object state) { if (MservProtocolLog.registryWatcher.IsChanged()) { using (RegistryKey registryKey = Registry.LocalMachine.OpenSubKey("SYSTEM\\CurrentControlSet\\Services\\MSExchange Mserv\\Parameters")) { bool registryBool = MservProtocolLog.GetRegistryBool(registryKey, "ProtocolLoggingEnabled", true); if (registryBool != MservProtocolLog.Enabled) { lock (MservProtocolLog.logLock) { MservProtocolLog.Initialized = false; MservProtocolLog.Enabled = registryBool; } } } } }