Exemple #1
0
 public void Enrich(LogEvent logEvent, ILogEventPropertyFactory propertyFactory)
 {
     // origin: https://nblumhardt.com/2015/10/assigning-event-types-to-serilog-events/
     logEvent.AddPropertyIfAbsent(propertyFactory.CreateProperty(
                                      LogEventPropertyKeys.EventType,
                                      BitConverter.ToUInt32(HashAlgorithm.ComputeHash(Encoding.UTF8.GetBytes(logEvent.MessageTemplate.Text)), 0)));
 }
        public override Key Transform(string key)
        {
            using (var byteKey = base.Transform(key))
            {
                var hash  = Murmur32.ComputeHash(byteKey.Array, 0, byteKey.Length);
                var array = allocator.Take(4);
                NetworkOrderConverter.EncodeUInt32(hash, array, 0);

                return(new Key(allocator, array, 4));
            }
        }
        public static string GetMurmurHash(this byte[] bytes)
        {
            var hashBytes = MurmurHash3.ComputeHash(bytes);
            var builder   = new StringBuilder();

            foreach (var b in hashBytes)
            {
                builder.AppendFormat("{0:x2}", b);
            }

            return(builder.ToString());
        }
Exemple #4
0
        public override Key Transform(string key)
        {
            using (var tmp = base.Transform(key))
            {
                var retval = new Key(allocator, 4);
                var hash   = Murmur32.ComputeHash(tmp.Array, 0, tmp.Length);

                NetworkOrderConverter.EncodeUInt32(hash, retval.Array, 0);

                return(retval);
            }
        }
Exemple #5
0
        public long MurMurHashByDarrenkopp()
        {
            long result = 0;

            unchecked
            {
                foreach (var bytes in _byteArrays)
                {
                    var hash = murMurDarrenkopp.ComputeHash(bytes);
                    result += BitConverter.ToUInt32(hash);
                }
            }

            return(result);
        }
        public long MurMurHashByDarrenkopp()
        {
            long result = 0;

            unchecked
            {
                foreach (var str in _strings)
                {
                    var hash = murMurDarrenkopp.ComputeHash(Encoding.UTF8.GetBytes(str));
                    result += BitConverter.ToUInt32(hash);
                }
            }

            return(result);
        }
        public void Enrich(LogEvent logEvent, ILogEventPropertyFactory propertyFactory)
        {
            if (logEvent == null)
            {
                throw new ArgumentNullException(nameof(logEvent));
            }

            if (propertyFactory == null)
            {
                throw new ArgumentNullException(nameof(propertyFactory));
            }

            Murmur32 murmur = MurmurHash.Create32();

            byte[]           bytes           = Encoding.UTF8.GetBytes(logEvent.MessageTemplate.Text);
            byte[]           hash            = murmur.ComputeHash(bytes);
            string           hexadecimalHash = BitConverter.ToString(hash).Replace("-", "");
            LogEventProperty eventId         = propertyFactory.CreateProperty("EventType", hexadecimalHash);

            logEvent.AddPropertyIfAbsent(eventId);
        }
Exemple #8
0
        public static uint ComputeHash32(this Murmur32 murmur, byte[] data)
        {
            var hash32 = murmur.ComputeHash(data);

            return(BitConverter.ToUInt32(hash32, 0));
        }