Ejemplo n.º 1
0
        public ILog Apply(ILog log)
        {
            IMask mask  = null;
            var   items = log.GetFields().ToList();
            var   copy  = new List <KeyValuePair <string, object> >();

            foreach (var item in items)
            {
                if (_masks.TryGetValue(item.Key, out mask) == false)
                {
                    copy.Add(item);
                }
                else
                {
                    var value = item.Value as string;
                    if (value == null)
                    {
                        copy.Add(item);
                    }
                    else
                    {
                        try
                        {
                            copy.Add(new KeyValuePair <string, object>(item.Key, mask.Mask(item.Value.ToString())));
                        }
                        catch
                        {
                            copy.Add(new KeyValuePair <string, object>(item.Key, KeyStore.Masking.MaskingFailed));
                            copy.Add(new KeyValuePair <string, object>(KeyStore.Masking.MaskingFailedKey, true));
                        }
                    }
                }
            }
            return(new SimpleLog(log.Id, log.LogTime, copy, log.Filters));
        }