public override int GetHashCode()
        {
            var hash = 1;

            if (HasKeyData)
            {
                hash ^= KeyData.GetHashCode();
            }
            if (HasTransmissionRiskLevel)
            {
                hash ^= TransmissionRiskLevel.GetHashCode();
            }
            if (HasRollingStartIntervalNumber)
            {
                hash ^= RollingStartIntervalNumber.GetHashCode();
            }
            if (HasRollingPeriod)
            {
                hash ^= RollingPeriod.GetHashCode();
            }
            if (_unknownFields != null)
            {
                hash ^= _unknownFields.GetHashCode();
            }

            return(hash);
        }
        public override int GetHashCode()
        {
            int hash = 1;

            if (HasKeyData)
            {
                hash ^= KeyData.GetHashCode();
            }
            if (HasTransmissionRiskLevel)
            {
                hash ^= TransmissionRiskLevel.GetHashCode();
            }
            if (HasRollingStartIntervalNumber)
            {
                hash ^= RollingStartIntervalNumber.GetHashCode();
            }
            if (HasRollingPeriod)
            {
                hash ^= RollingPeriod.GetHashCode();
            }
            if (HasReportType)
            {
                hash ^= ReportType.GetHashCode();
            }
            if (HasDaysSinceOnsetOfSymptoms)
            {
                hash ^= DaysSinceOnsetOfSymptoms.GetHashCode();
            }
            if (_unknownFields != null)
            {
                hash ^= _unknownFields.GetHashCode();
            }
            return(hash);
        }
        /// <summary>
        /// Adds a sink that writes log events as documents to a LiteDb database.
        /// </summary>
        /// <param name="loggerConfiguration">The logger configuration.</param>
        /// <param name="databaseUrl">The URL of a created LiteDB collection that log events will be written to.</param>
        /// <param name="logCollectionName">Name of the collection. Default is "log".</param>
        /// <param name="rollingFilePeriod">Which period must be used to create a new file. 'Never' value applies default behavior (never create a new file)</param>
        /// <param name="restrictedToMinimumLevel">The minimum log event level required in order to write an event to the sink.</param>
        /// <param name="batchPostingLimit">The batch posting limit.</param>
        /// <param name="period">The period.</param>
        /// <param name="formatter">The formatter.</param>
        /// <returns>
        /// Logger configuration, allowing configuration to continue.
        /// </returns>
        /// <exception cref="System.ArgumentNullException">loggerConfiguration
        /// or
        /// databaseUrl</exception>
        /// <exception cref="ArgumentNullException">A required parameter is null.</exception>
        public static LoggerConfiguration LiteDB(
            this LoggerSinkConfiguration loggerConfiguration,
            string databaseUrl,
            string logCollectionName               = LiteDBSink.DefaultLogCollectionName,
            RollingPeriod rollingFilePeriod        = RollingPeriod.Never,
            LogEventLevel restrictedToMinimumLevel = LevelAlias.Minimum,
            int batchPostingLimit    = LiteDBSink.DefaultBatchPostingLimit,
            TimeSpan?period          = null,
            ITextFormatter formatter = null)
        {
            if (loggerConfiguration == null)
            {
                throw new ArgumentNullException(nameof(loggerConfiguration));
            }
            if (string.IsNullOrWhiteSpace(databaseUrl))
            {
                throw new ArgumentNullException(nameof(databaseUrl));
            }
            if (string.IsNullOrWhiteSpace(logCollectionName))
            {
                throw new ArgumentNullException(nameof(logCollectionName));
            }
            if (formatter == null)
            {
                formatter = LiteDBSink.DefaultFormatter;
            }

            return(loggerConfiguration.Sink(
                       new LiteDBSink(databaseUrl, rollingFilePeriod, batchPostingLimit, period, logCollectionName, formatter),
                       restrictedToMinimumLevel));
        }
Example #4
0
 /// <summary>
 /// Construct a sink posting to the specified database.
 /// </summary>
 /// <param name="connectionString">The URL of a LiteDB database, or connection string name containing the URL.</param>
 /// <param name="rollingPeriod">When to roll a new file</param>
 /// <param name="batchPostingLimit">The batch posting limit.</param>
 /// <param name="period">The period.</param>
 /// <param name="logCollectionName">Name of the LiteDb collection to use for the log. Default is "log".</param>
 /// <param name="formatter">The formatter. Default is <see cref="LiteDBJsonFormatter" /> used</param>
 public LiteDBSink(
     string connectionString,
     RollingPeriod rollingPeriod,
     int batchPostingLimit    = DefaultBatchPostingLimit,
     TimeSpan?period          = null,
     string logCollectionName = DefaultLogCollectionName,
     ITextFormatter formatter = null)
     : base(batchPostingLimit, period ?? DefaultPeriod)
 {
     _connectionString  = connectionString;
     _rollingPeriod     = rollingPeriod;
     _logCollectionName = logCollectionName;
     _formatter         = formatter;
 }
 public override int GetHashCode() {
     int hash = 1;
     if (KeyData.Length != 0) hash ^= KeyData.GetHashCode();
     if (RollingStartIntervalNumber != 0) hash ^= RollingStartIntervalNumber.GetHashCode();
     if (RollingPeriod != 0) hash ^= RollingPeriod.GetHashCode();
     if (TransmissionRiskLevel != 0) hash ^= TransmissionRiskLevel.GetHashCode();
     hash ^= visitedCountries_.GetHashCode();
     if (Origin.Length != 0) hash ^= Origin.GetHashCode();
     if (ReportType != global::Iks.Protobuf.EfgsReportType.Unknown) hash ^= ReportType.GetHashCode();
     if (DaysSinceOnsetOfSymptoms != 0) hash ^= DaysSinceOnsetOfSymptoms.GetHashCode();
     if (_unknownFields != null) {
         hash ^= _unknownFields.GetHashCode();
     }
     return hash;
 }
Example #6
0
        /// <summary>
        /// Parses the connection string and resolves the filename by using rolling period.
        /// </summary>
        /// <param name="connectionString">Connection string to bre parsed</param>
        /// <param name="period">Period</param>
        /// <param name="date">Date</param>
        /// <returns></returns>
        public static string GetFilename(string connectionString, RollingPeriod period, DateTime date)
        {
            if (period == RollingPeriod.Never)
            {
                return(connectionString);
            }

            var c        = ConnectionStringParser.Parse(connectionString);
            var fullpath = c["filename"];

            var filename   = Path.GetFileName(fullpath);
            var extension  = Path.GetExtension(filename);
            var file       = Path.GetFileNameWithoutExtension(filename);
            var folderPart = Path.GetDirectoryName(fullpath) ?? ("." + Path.DirectorySeparatorChar);
            var dateFormat = "yyyy-MM-dd-HHmm";

            switch (period)
            {
            case RollingPeriod.HalfHour:
            case RollingPeriod.Quarterly:
                var itv         = period == RollingPeriod.Quarterly ? 15 : 30;
                var dateMinutes = date.Minute / itv * itv;
                date = date.AddMinutes(-date.Minute).AddMinutes(dateMinutes);
                break;

            case RollingPeriod.Weekly:
            case RollingPeriod.Daily:
                dateFormat = "yyyy-MM-dd";
                break;

            case RollingPeriod.Monthly:

                dateFormat = "yyyy-MM";
                break;

            case RollingPeriod.Hourly:
                dateFormat = "yyyy-MM-dd-HH";
                break;

            default:
                throw new InvalidOperationException($"period cannot be parsed: {period}");
            }

            file          = file + "_" + date.ToString(dateFormat);
            c["filename"] = Path.Combine(folderPart, $"{file}{extension}");
            return(ConnectionStringParser.Create(c));
        }
Example #7
0
        public static void TestQuarterly()
        {
            const RollingPeriod period = RollingPeriod.Quarterly;

            var expected = "filename=c:\\tmp\\file_1950-01-12-1000.db";
            var file     = FileRoller.GetFilename(connStr, period, new DateTime(1950, 01, 12, 10, 4, 0));

            Debug.Assert(expected == file);
            expected = "filename=c:\\tmp\\file_1950-01-12-1000.db";
            file     = FileRoller.GetFilename(connStr, period, new DateTime(1950, 01, 12, 10, 14, 0));
            Debug.Assert(expected == file);

            expected = "filename=c:\\tmp\\file_1950-01-12-1015.db";
            file     = FileRoller.GetFilename(connStr, period, new DateTime(1950, 01, 12, 10, 15, 0));
            Debug.Assert(expected == file);

            expected = "filename=c:\\tmp\\file_1950-01-12-1030.db";
            file     = FileRoller.GetFilename(connStr, period, new DateTime(1950, 01, 12, 10, 30, 0));
            Debug.Assert(expected == file);
        }
Example #8
0
        public override int GetHashCode()
        {
            int hash = 1;

            if (KeyData.Length != 0)
            {
                hash ^= KeyData.GetHashCode();
            }
            if (RollingStartIntervalNumber != 0)
            {
                hash ^= RollingStartIntervalNumber.GetHashCode();
            }
            if (RollingPeriod != 0)
            {
                hash ^= RollingPeriod.GetHashCode();
            }
            if (TransmissionRiskLevel != 0)
            {
                hash ^= TransmissionRiskLevel.GetHashCode();
            }
            hash ^= visitedCountries_.GetHashCode();
            if (Origin.Length != 0)
            {
                hash ^= Origin.GetHashCode();
            }
            if (ReportType != global::FederationGatewayApi.Models.Proto.TemporaryExposureKeyGatewayDto.Types.ReportType.Unknown)
            {
                hash ^= ReportType.GetHashCode();
            }
            if (DaysSinceOnsetOfSymptoms != 0)
            {
                hash ^= DaysSinceOnsetOfSymptoms.GetHashCode();
            }
            if (_unknownFields != null)
            {
                hash ^= _unknownFields.GetHashCode();
            }
            return(hash);
        }
        public void FormatSuffix_should_use_correct_time_format_for_Second_period()
        {
            rollingPeriod = RollingPeriod.Second;

            suffixFormatter.FormatSuffix(DateTime.Parse("2018-08-31T06:24:13")).Should().Be("-2018-08-31-06-24-13");
        }
Example #10
0
        public void FormatSuffix_should_use_correct_time_format_for_Day_period()
        {
            rollingPeriod = RollingPeriod.Day;

            suffixFormatter.FormatSuffix(DateTime.Parse("2018-08-31T06:24:13")).Should().Be("2018-08-31");
        }