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

            actual.Should().Be(expected);
        }
コード例 #2
0
 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
ファイル: LogProperty.cs プロジェクト: kbabiy/LogCast
        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);
            }
        }
コード例 #15
0
 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
ファイル: LogProperty.cs プロジェクト: kbabiy/LogCast
 /// <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
ファイル: LogProperty.cs プロジェクト: kbabiy/LogCast
 protected internal sealed override void Apply(LogCastDocument document)
 {
     Apply(document, Value);
 }
コード例 #25
0
ファイル: LogProperty.cs プロジェクト: kbabiy/LogCast
 /// <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);
 }
コード例 #28
0
 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);
 }
コード例 #30
0
 protected override void SetFields(LogCastDocument document)
 {
     document.AddProperty("new_line", "\nvalue");
 }