Esempio n. 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);
 }
Esempio n. 3
0
        public override void Act()
        {
            Logger.Warn(TestMessage);
            Logger.Error(SecondTestMessage);
            Complete();

            _lastLog = ClientMock.LastLog;
        }
Esempio n. 4
0
 protected virtual void SendTestMessage()
 {
     Sut.Send(() =>
     {
         var doc = new LogCastDocument();
         doc.AddProperty("testKey", "testValue");
         return(doc);
     });
 }
Esempio n. 5
0
        public void BeforeSend(LogCastDocument document, LogCastContext sourceContext)
        {
            var source = OperationContext.Current;

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

            if (context != null)
            {
                Apply(document, context);
            }
        }
Esempio n. 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" }
     });
 }
Esempio n. 8
0
 protected override void SetFields(LogCastDocument document)
 {
     document.AddProperty("complex_object", new RootObject
     {
         Property1     = "rootvalue",
         Property2     = 23,
         ChildProperty = new ChildObject
         {
             Property3 = "childvalue"
         }
     });
 }
Esempio n. 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);
            }
        }
Esempio n. 10
0
        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);
        }
Esempio n. 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);
            }
        }
Esempio n. 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);
            }
        }
Esempio n. 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;
        }
Esempio n. 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");
 }
Esempio n. 16
0
 protected override void SetFields(LogCastDocument document)
 {
     document.AddProperty("key1", "value1");
     document.AddProperty("key2", "value2");
 }
Esempio n. 17
0
 public override void Arrange()
 {
     Accumulator = new PropertyAccumulator();
     Document    = new LogCastDocument();
 }
Esempio n. 18
0
 protected override void SetFields(LogCastDocument document)
 {
     document.AddProperty("string", (string)null, true);
     document.AddProperty("someKey", "someValue");
     document.AddProperty("int", 0, true);
 }
Esempio n. 19
0
 /// <summary>
 /// Stores property value to the passed <see cref="LogCastDocument"/>
 /// </summary>
 protected internal abstract void Apply(LogCastDocument document);
Esempio n. 20
0
 public void BeforeSend(LogCastDocument document, LogCastContext sourceContext)
 {
     Apply(document);
 }
Esempio n. 21
0
 protected abstract void SetFields(LogCastDocument document);
Esempio n. 22
0
 private static string Json(object obj)
 {
     return(LogCastDocument.ToJson(obj));
 }
Esempio n. 23
0
 public override void Arrange()
 {
     Document = new LogCastDocument();
     SetFields(Document);
 }
Esempio n. 24
0
 protected internal sealed override void Apply(LogCastDocument document)
 {
     Apply(document, Value);
 }
Esempio n. 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);
Esempio n. 26
0
 public override void Arrange()
 {
     _cut = new LogCastDocument();
 }
Esempio n. 27
0
 public void BeforeSend(LogCastDocument document, LogMessage sourceMessage)
 {
     Apply(document);
 }
 protected override void SetFields(LogCastDocument document)
 {
     document.AddProperty("carriage_return", "\rvalue");
 }
Esempio n. 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");
 }