示例#1
0
        private IAppender CreateSiteAppender()
        {
            OrchardFileAppender appender = new OrchardFileAppender();

            appender.Name         = GetAppenderName();
            appender.File         = GetAppenderFileName();
            appender.AppendToFile = true;
            // Allow extended character sets
            appender.Encoding = Encoding.UTF8;
            // Immediately flush on error to avoid data loss
            appender.ImmediateFlush = true;
            // Filename will also depend on date
            appender.StaticLogFileName = false;
            appender.RollingStyle      = RollingFileAppender.RollingMode.Date;
            appender.DatePattern       = $"{LaserAuditTrailHelper.GetAppenderDatePattern()}'.{LaserAuditTrailHelper.GetAppenderFileExtension()}'";
            // Prevent Orchard from displaying locking debug messages
            appender.LockingModel = new FileAppender.MinimalLock();
            // Filters
            var stringMatchFilter = new log4net.Filter.StringMatchFilter();

            stringMatchFilter.StringToMatch = _logMatchString;
            appender.AddFilter(stringMatchFilter);
            appender.AddFilter(new log4net.Filter.DenyAllFilter());
            // Log Layout
            var layout = new log4net.Layout.PatternLayout(
                @"%date %logger - %P{Tenant} - %level% [ExecutionId=%P{ExecutionId}]%newline[%P{Url}]%newline%message%newline "
                );

            layout.ActivateOptions();
            appender.Layout = layout;
            appender.ActivateOptions();
            return(appender);
        }
 public void Sweep()
 {
     Logger.Debug("Beginning sweep for TrailLogTrimmingBackgroundTask.");
     try {
         // This task should look for audit trail log files older than a timespan
         // and delete them if any are found.
         if (GetIsTimeToTrim())
         {
             var logFilePath       = LaserAuditTrailHelper.GetLogsFilePath();
             var logFileExtension  = LaserAuditTrailHelper.GetAppenderFileExtension();
             var fileNameBeginning = Path.Combine(
                 logFilePath,
                 LaserAuditTrailHelper.GetAppenderFileName(
                     GetSiteSettings().SiteName))
                                     .Replace(Path.DirectorySeparatorChar, '/');
             var myLogs = _appDataFolder
                          .ListFiles(logFilePath)
                          .Where(fn => fn.StartsWith(fileNameBeginning));
             // get the logs older than the specific timespan and delete them
             // Retention timespan: anything older will be deleted
             var retentionPeriod = TimeSpan.FromDays(GetAuditTrailSettings().RetentionPeriod);
             var dateThreshold   = (_clock.UtcNow.EndOfDay() - retentionPeriod);
             foreach (var fileName in myLogs)
             {
                 var lastWriteTime = _appDataFolder.GetFileLastWriteTimeUtc(fileName);
                 if (lastWriteTime <= dateThreshold)
                 {
                     // file is older than the limit for retention. Delete it.
                     _appDataFolder.DeleteFile(fileName);
                 }
             }
         }
     } catch (Exception ex) {
         Logger.Error(ex, "Error during sweep for TrailLogTrimmingBackgroundTask.");
     } finally {
         Logger.Debug("Ending sweep for TrailLogTrimmingBackgroundTask.");
     }
 }
示例#3
0
 private string GetAppenderFileName()
 {
     return(Path.Combine(
                LaserAuditTrailHelper.GetAppenderFilePath(),
                LaserAuditTrailHelper.GetAppenderFileName(GetSiteSettings().SiteName)));
 }
示例#4
0
 private string GetAppenderName()
 {
     return(LaserAuditTrailHelper.GetAppenderName(GetSiteSettings().SiteName));
 }