protected void PublishMonitoringResult(int numberofAttemptsAfterLastSuccess, ExDateTime firstFailedSyncTimeAfterLastSuccess, ExDateTime lastFailedSyncTime)
        {
            TimeSpan t = lastFailedSyncTime - firstFailedSyncTimeAfterLastSuccess;

            if (numberofAttemptsAfterLastSuccess >= PublicFolderMailboxLogger.MinNumberOfFailedSyncAttemptsForAlert && t >= PublicFolderMailboxLogger.MinDurationOfSyncFailureForAlert)
            {
                string name      = ExchangeComponent.PublicFolders.Name;
                string component = "PublicFolderMailboxSync";
                string empty     = string.Empty;
                EventNotificationItem eventNotificationItem = new EventNotificationItem(name, component, empty, ResultSeverityLevel.Error);
                eventNotificationItem.StateAttribute1 = this.pfSession.MailboxGuid.ToString();
                eventNotificationItem.StateAttribute2 = this.pfSession.MdbGuid.ToString();
                eventNotificationItem.StateAttribute3 = ((this.pfSession.OrganizationId.OrganizationalUnit != null) ? this.pfSession.OrganizationId.OrganizationalUnit.Name.ToString() : string.Empty);
                if (this.LastError == null)
                {
                    eventNotificationItem.Message = "No LastError but failing for at least this long: " + PublicFolderMailboxLogger.MinDurationOfSyncFailureForAlert;
                }
                else
                {
                    eventNotificationItem.Message = PublicFolderMailboxLoggerBase.GetExceptionLogString(this.LastError, PublicFolderMailboxLoggerBase.ExceptionLogOption.All);
                }
                try
                {
                    eventNotificationItem.Publish(false);
                }
                catch (UnauthorizedAccessException e)
                {
                    this.LogEvent(LogEventType.Warning, string.Format("PublishMonitoringResult: Failed with exception {0}", PublicFolderMailboxLoggerBase.GetExceptionLogString(e, PublicFolderMailboxLoggerBase.ExceptionLogOption.All)));
                }
                catch (EventLogNotFoundException e2)
                {
                    this.LogEvent(LogEventType.Warning, string.Format("PublishMonitoringResult: Failed with exception {0}", PublicFolderMailboxLoggerBase.GetExceptionLogString(e2, PublicFolderMailboxLoggerBase.ExceptionLogOption.All)));
                }
            }
        }
 public virtual void ReportError(string errorContextMessage, Exception syncException)
 {
     this.LogEvent(LogEventType.Error, string.Format(CultureInfo.InvariantCulture, "[ErrorContext:{0}] {1}", new object[]
     {
         errorContextMessage,
         PublicFolderMailboxLoggerBase.GetExceptionLogString(syncException, PublicFolderMailboxLoggerBase.ExceptionLogOption.All)
     }));
 }
        internal static void LogOnServer(string data, LogEventType eventType, string logComponent, string logSuffixName, Guid?transactionId = null)
        {
            Log             log             = PublicFolderMailboxLoggerBase.InitializeServerLogging(logComponent, logSuffixName);
            LogRowFormatter logRowFormatter = new LogRowFormatter(PublicFolderMailboxLoggerBase.LogSchema);

            logRowFormatter[2] = eventType;
            logRowFormatter[5] = data;
            if (transactionId != null)
            {
                logRowFormatter[7] = transactionId;
            }
            log.Append(logRowFormatter, 0);
        }
 public bool TrySave()
 {
     try
     {
         this.LogFinalFoldersStats();
         if (this.LastError == null)
         {
             this.SetSyncMetadataValue("NumberofAttemptsAfterLastSuccess", 0);
             this.SetSyncMetadataValue("FirstFailedSyncTimeAfterLastSuccess", null);
             this.LogEvent(LogEventType.Success, "Diagnostics for monitoring is successfully completed");
             this.SetSyncMetadataValue("LastSuccessfulSyncTime", ExDateTime.UtcNow);
         }
         else
         {
             this.SetSyncMetadataValue("LastSyncFailure", PublicFolderMailboxLoggerBase.GetExceptionLogString(this.LastError, PublicFolderMailboxLoggerBase.ExceptionLogOption.All));
             int num;
             this.TryGetSyncMetadataValue <int>("NumberofAttemptsAfterLastSuccess", out num);
             num++;
             this.SetSyncMetadataValue("NumberofAttemptsAfterLastSuccess", num);
             this.LogEvent(LogEventType.Error, "Diagnostics for monitoring is failed");
             ExDateTime utcNow = ExDateTime.UtcNow;
             this.SetSyncMetadataValue("LastFailedSyncTime", utcNow);
             ExDateTime exDateTime = default(ExDateTime);
             this.TryGetSyncMetadataValue <ExDateTime>("FirstFailedSyncTimeAfterLastSuccess", out exDateTime);
             if (num == 1 || exDateTime == default(ExDateTime))
             {
                 exDateTime = utcNow;
                 this.SetSyncMetadataValue("FirstFailedSyncTimeAfterLastSuccess", exDateTime);
             }
             this.PublishMonitoringResult(num, exDateTime, utcNow);
         }
         this.gZipLoggingStream.Dispose();
         this.gZipLoggingStream = null;
         this.loggingStream.Dispose();
         this.loggingStream = null;
         this.diagnosticsMetadata.Save();
         this.lastCycleLogMetadata.Save();
         return(true);
     }
     catch (StorageTransientException exception)
     {
         PublicFolderMailboxLoggerBase.LogOnServer(exception, this.logComponent, this.logSuffixName);
     }
     catch (StoragePermanentException exception2)
     {
         PublicFolderMailboxLoggerBase.LogOnServer(exception2, this.logComponent, this.logSuffixName);
     }
     return(false);
 }
 private static Log InitializeServerLogging(string logComponent, string logSuffixName)
 {
     if (!PublicFolderMailboxLoggerBase.initializedLogs.ContainsKey(logSuffixName))
     {
         lock (PublicFolderMailboxLoggerBase.initializeLockObject)
         {
             if (!PublicFolderMailboxLoggerBase.initializedLogs.ContainsKey(logSuffixName))
             {
                 Log log = new Log(PublicFolderMailboxLoggerBase.GetLogFileName(logSuffixName), new LogHeaderFormatter(PublicFolderMailboxLoggerBase.LogSchema), logComponent);
                 log.Configure(Path.Combine(ExchangeSetupContext.InstallPath, "Logging\\PublicFolder\\"), PublicFolderMailboxLoggerBase.LogMaxAge, 262144000L, 10485760L);
                 PublicFolderMailboxLoggerBase.initializedLogs.Add(logSuffixName, log);
             }
         }
     }
     return(PublicFolderMailboxLoggerBase.initializedLogs[logSuffixName]);
 }
        public virtual void LogEvent(LogEventType eventType, string data, out LogRowFormatter row)
        {
            if (string.IsNullOrEmpty(data))
            {
                throw new ArgumentNullException("data");
            }
            Log log = PublicFolderMailboxLoggerBase.InitializeServerLogging(this.logComponent, this.logSuffixName);

            row    = new LogRowFormatter(PublicFolderMailboxLoggerBase.LogSchema);
            row[2] = eventType;
            row[3] = this.organizationId.ToString();
            row[4] = this.MailboxGuid.ToString();
            row[7] = this.TransactionId.ToString();
            row[5] = data;
            log.Append(row, 0);
        }
 internal static void LogOnServer(Exception exception, string logComponent, string logSuffixName)
 {
     PublicFolderMailboxLoggerBase.LogOnServer(PublicFolderMailboxLoggerBase.GetExceptionLogString(exception, PublicFolderMailboxLoggerBase.ExceptionLogOption.All), LogEventType.Error, logComponent, logSuffixName, null);
 }