예제 #1
0
        public void then_flattenned_correctly(object input, string expected)
        {
            Act(input);
            var actual = LogCastDocument.ToJson(Request.Route.SerializedValues);

            actual.Should().Be(expected);
        }
 protected override void SetFields(LogCastDocument document)
 {
     _value = new Dictionary <string, int> {
         { "key1", 23 }, { "key2", 24 }
     };
     document.AddProperty("key", _value);
 }
예제 #3
0
        public override void Act()
        {
            Logger.Warn(TestMessage);
            Logger.Error(SecondTestMessage);
            Complete();

            _lastLog = ClientMock.LastLog;
        }
예제 #4
0
파일: Context.cs 프로젝트: 7digital/LogCast
 protected virtual void SendTestMessage()
 {
     Sut.Send(() =>
     {
         var doc = new LogCastDocument();
         doc.AddProperty("testKey", "testValue");
         return(doc);
     });
 }
예제 #5
0
        public void BeforeSend(LogCastDocument document, LogCastContext sourceContext)
        {
            var source = OperationContext.Current;

            if (source != null)
            {
                Apply(document, source);
            }
        }
예제 #6
0
        public void BeforeSend(LogCastDocument document, LogCastContext sourceContext)
        {
            var context = HttpContext.Current;

            if (context != null)
            {
                Apply(document, context);
            }
        }
예제 #7
0
 protected override void SetFields(LogCastDocument document)
 {
     document.AddProperty("key1", "simple.value1");
     document.AddProperty("simple.property", "simple.value2");
     document.AddProperty("dictionary.property",
                          new Dictionary <string, string>
     {
         { "key", "value" },
         { "key.with.dots", "value.with.dots" }
     });
 }
예제 #8
0
 protected override void SetFields(LogCastDocument document)
 {
     document.AddProperty("complex_object", new RootObject
     {
         Property1     = "rootvalue",
         Property2     = 23,
         ChildProperty = new ChildObject
         {
             Property3 = "childvalue"
         }
     });
 }
예제 #9
0
        protected virtual void Apply(LogCastDocument target, HttpContext context)
        {
            var root = new Root();

            if (Options.IsRequestLogged)
            {
                var request     = context.Request;
                var requestData = new Request();
                if (Options.LogRequestUri)
                {
                    requestData.Uri = GetRequestUri(request).AbsoluteUri;
                }
                if (Options.LogRequestMethod)
                {
                    requestData.Method = request.HttpMethod;
                }
                if (Options.LogRequestHeaders)
                {
                    requestData.Headers = CollectHeadersSafely(request.Headers);
                }
                if (Options.LogRequestBody)
                {
                    requestData.Body = ReadRequestBody(request);
                }

                root.Request = requestData;
            }

            if (Options.IsResponseLogged)
            {
                var response     = context.Response;
                var responseData = new Response();
                if (Options.LogResponseStatus)
                {
                    responseData.Status = response.StatusCode;
                }
                if (Options.LogResponseHeaders)
                {
                    responseData.Headers = CollectHeadersSafely(response.Headers);
                }
                if (Options.LogResponseBody)
                {
                    responseData.Body = ReadResponseBody(response);
                }

                root.Response = responseData;
            }

            if (root.HasData)
            {
                target.AddProperty(Root.FieldName, root);
            }
        }
예제 #10
0
파일: when_ran.cs 프로젝트: kbabiy/LogCast
        public void then_contract_serialized_is_as_expected()
        {
            var actualSerialized = LogCastDocument.ToJson(Request.Route);
            var expected = LogCastDocument.ToJson(new
            {
                template = "",
                controller = (string)null,
                action = (string)null,
                values = new {key = "value"}
            });

            actualSerialized.Should().Be(expected);
        }
예제 #11
0
        protected virtual void Apply <TDestination>(LogCastDocument document, TDestination value)
        {
            var existingValue = document.GetProperty <object>(Key);

            if (existingValue is Dictionary <string, object> childDictionary)
            {
                childDictionary[Property.DefaultChildName] = value;
            }
            else
            {
                document.AddProperty(Name, value, SuppressDefaults);
            }
        }
예제 #12
0
        protected virtual void Apply(LogCastDocument target, OperationContext source)
        {
            var root = new Root();

            if (Options.IsRequestLogged)
            {
                var request = new Request();
                if (Options.LogCallerAddress)
                {
                    request.Caller = GetCallerAddress(source.IncomingMessageProperties);
                }
                if (Options.LogRequestProperties)
                {
                    request.Properties = CollectProperties(source.IncomingMessageProperties);
                }
                if (Options.LogRequestHttpData)
                {
                    request.HttpHeaders = CollectHttpRequestHeaders(source.IncomingMessageProperties);
                }
                if (Options.LogRequestBody)
                {
                    request.Body = source.RequestContext?.RequestMessage?.ToString();
                }

                root.Request = request;
            }

            if (Options.IsResponseLogged)
            {
                var response = new Response();
                if (Options.LogResponseProperties)
                {
                    response.Properties = CollectProperties(source.OutgoingMessageProperties);
                }
                if (Options.LogResponseHttpData)
                {
                    response.HttpHeaders = CollectHttpResponseHeaders(source.OutgoingMessageProperties);
                }

                root.Response = response;
            }

            if (root.HasData)
            {
                target.AddProperty(Root.FieldName, root);
            }
        }
예제 #13
0
        protected override void Apply <TDestination>(LogCastDocument document, TDestination value)
        {
            var existingValue = document.GetProperty <object>(ParentName);

            if (existingValue is Dictionary <string, object> childDictionary)
            {
                existingValue = null;
            }
            else
            {
                childDictionary = new Dictionary <string, object>();
                document.AddProperty(ParentName, childDictionary);
            }

            if (existingValue != null)
            {
                childDictionary[Property.DefaultChildName] = existingValue;
            }

            childDictionary[Name] = value;
        }
예제 #14
0
        public static string RemoveSensitiveData(string body)
        {
            if (string.IsNullOrWhiteSpace(body))
            {
                return(null);
            }

            if (SensitiveInformationKeywords.All(x => body.IndexOf(x, StringComparison.OrdinalIgnoreCase) == -1))
            {
                return(body);
            }

            try
            {
                var jsonBody = JObject.Parse(body);
                if (jsonBody == null)
                {
                    return(Property.Values.Removed);
                }

                var keys = ((IDictionary <string, JToken>)jsonBody)
                           .Where(x => SensitiveInformationKeywords.Contains(x.Key, StringComparer.OrdinalIgnoreCase))
                           .Select(x => x.Key);

                foreach (var keyValuePair in keys)
                {
                    jsonBody[keyValuePair] = Property.Values.Removed;
                }

                return(LogCastDocument.ToJson(jsonBody));
            }
            catch (Exception)
            {
                return(Property.Values.Removed);
            }
        }
 protected override void SetFields(LogCastDocument document)
 {
     document.AddProperty("tab", "\tvalue");
 }
예제 #16
0
 protected override void SetFields(LogCastDocument document)
 {
     document.AddProperty("key1", "value1");
     document.AddProperty("key2", "value2");
 }
예제 #17
0
 public override void Arrange()
 {
     Accumulator = new PropertyAccumulator();
     Document    = new LogCastDocument();
 }
예제 #18
0
 protected override void SetFields(LogCastDocument document)
 {
     document.AddProperty("string", (string)null, true);
     document.AddProperty("someKey", "someValue");
     document.AddProperty("int", 0, true);
 }
예제 #19
0
 /// <summary>
 /// Stores property value to the passed <see cref="LogCastDocument"/>
 /// </summary>
 protected internal abstract void Apply(LogCastDocument document);
예제 #20
0
 public void BeforeSend(LogCastDocument document, LogCastContext sourceContext)
 {
     Apply(document);
 }
예제 #21
0
 protected abstract void SetFields(LogCastDocument document);
예제 #22
0
 private static string Json(object obj)
 {
     return(LogCastDocument.ToJson(obj));
 }
예제 #23
0
 public override void Arrange()
 {
     Document = new LogCastDocument();
     SetFields(Document);
 }
예제 #24
0
 protected internal sealed override void Apply(LogCastDocument document)
 {
     Apply(document, Value);
 }
예제 #25
0
 /// <summary>
 /// Aggregates values of the passed properties and stores the result to the passed <see cref="LogCastDocument"/>
 /// This method is called only when there's more than one property with the same name
 /// </summary>
 protected internal abstract void Apply(LogCastDocument document, IEnumerable <LogProperty> properties);
예제 #26
0
 public override void Arrange()
 {
     _cut = new LogCastDocument();
 }
예제 #27
0
 public void BeforeSend(LogCastDocument document, LogMessage sourceMessage)
 {
     Apply(document);
 }
 protected override void SetFields(LogCastDocument document)
 {
     document.AddProperty("carriage_return", "\rvalue");
 }
예제 #29
0
 private void Apply(LogCastDocument document)
 {
     document.AddProperty(Property.Host, _hostData);
     document.AddProperty(Property.AppVersion, _appVersion);
     document.AddProperty(Property.Logging.Name, Property.Logging.LibVersion, _libVersion);
 }
 protected override void SetFields(LogCastDocument document)
 {
     document.AddProperty("new_line", "\nvalue");
 }