当前位置: 首页>>代码示例>>C#>>正文


C# IFormatterLogger.LogError方法代码示例

本文整理汇总了C#中IFormatterLogger.LogError方法的典型用法代码示例。如果您正苦于以下问题:C# IFormatterLogger.LogError方法的具体用法?C# IFormatterLogger.LogError怎么用?C# IFormatterLogger.LogError使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在IFormatterLogger的用法示例。


在下文中一共展示了IFormatterLogger.LogError方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: ReadFromStreamAsync

        /// <summary>
        /// Asynchronously deserializes an object of the specified type.
        /// </summary>
        /// <param name="type">The type of the object to deserialize.</param>
        /// <param name="readStream">The <see cref="T:System.IO.Stream" /> to read.</param>
        /// <param name="content">The <see cref="T:System.Net.Http.HttpContent" />, if available. It may be null.</param>
        /// <param name="formatterLogger">The <see cref="T:System.Net.Http.Formatting.IFormatterLogger" /> to log events to.</param>
        /// <returns>
        /// A <see cref="T:System.Threading.Tasks.Task" /> whose result will be an object of the given type.
        /// </returns>
        public override Task<object> ReadFromStreamAsync(Type type, Stream readStream, System.Net.Http.HttpContent content, IFormatterLogger formatterLogger)
        {
            var tcs = new TaskCompletionSource<object>();

            try
            {
                var reader = GetJsonReader(readStream);
                using (reader)
                {
                    var jsonSerializerSettings = new JsonSerializerSettings();
                    jsonSerializerSettings.Converters.Add(new HyperNewtonsoftJsonConverter());
                    var jsonSerializer = JsonSerializer.Create(jsonSerializerSettings);
                    var output = jsonSerializer.Deserialize(reader, type);
                    if (formatterLogger != null)
                    {
                        jsonSerializer.Error += (sender, e) =>
                            {
                                var exception = e.ErrorContext.Error;
                                formatterLogger.LogError(e.ErrorContext.Path, exception.Message);
                                e.ErrorContext.Handled = true;
                            };
                    }
                    tcs.SetResult(output);
                }
            }
            catch (Exception e)
            {
                if (formatterLogger == null) throw;
                formatterLogger.LogError(String.Empty, e.Message);
                tcs.SetResult(GetDefaultValueForType(type));
            }

            return tcs.Task;
        }
开发者ID:tmitchel2,项目名称:Hyper,代码行数:44,代码来源:NewtonsoftJsonMediaTypeFormatter.cs

示例2: ReadFromStreamAsync

        public override Task<object> ReadFromStreamAsync(Type type, Stream readStream, HttpContent content, IFormatterLogger formatterLogger) {
            if (!DocumentUpgrader.Current.CanUpgradeType(type))
                return base.ReadFromStreamAsync(type, readStream, content, formatterLogger);

            Task<object> task = Task<object>.Factory.StartNew(() => {
                using (var reader = new StreamReader(readStream)) {
                    string json = reader.ReadToEnd();

                    try {
                        if (Settings.Current.SaveIncomingErrorsToDisk)
                            File.WriteAllText(String.Format("{0}\\{1}.json", Settings.Current.IncomingErrorPath, Guid.NewGuid().ToString("N")), json);
                    } catch (Exception ex) {
                        formatterLogger.LogError(String.Empty, ex);
                    }

                    try {
                        JObject document = JObject.Parse(json);
                        DocumentUpgrader.Current.Upgrade(document, type);
                        return JsonConvert.DeserializeObject(document.ToString(), type);
                    } catch (Exception ex) {
                        ex.ToExceptionless().AddObject(json, "Error").Submit();
                        formatterLogger.LogError(String.Empty, ex);
                        throw;
                    }
                }
            });

            return task;
        }
开发者ID:khoussem,项目名称:Exceptionless,代码行数:29,代码来源:UpgradableJsonMediaTypeFormatter.cs

示例3: ReadFromStream

        private object ReadFromStream(Type type, Stream readStream, HttpContent content, IFormatterLogger formatterLogger)
        {
            var root = GetRootFieldName(type);
            var contentHeaders = content == null ? null : content.Headers;

            // If content length is 0 then return default value for this type
            if (contentHeaders != null && contentHeaders.ContentLength == 0)
                return GetDefaultValueForType(type);

            // Get the character encoding for the content
            var effectiveEncoding = SelectCharacterEncoding(contentHeaders);

            try
            {
                using (var reader = (new StreamReader(readStream, effectiveEncoding)))
                {
                    var json = reader.ReadToEnd();
                    var serializer = new EmberJsonSerializer();
                    var deserialized = serializer.Deserialize(json, root);
                    return deserialized.ToObject(type);
                }
            }
            catch (Exception e)
            {
                if (formatterLogger == null)
                {
                    throw;
                }
                formatterLogger.LogError(String.Empty, e);
                return GetDefaultValueForType(type);
            }
        }
开发者ID:dpollock,项目名称:EmberJS.WebAPI,代码行数:32,代码来源:EmberJsonMediaTypeFormatter.cs

示例4: ReadFromStreamAsync

        public override Task<object> ReadFromStreamAsync(Type type, Stream readStream, System.Net.Http.HttpContent content, IFormatterLogger formatterLogger)
        {
            var taskCompletionSource = new TaskCompletionSource<object>();

            try
            {
                BsonReader reader = new BsonReader(readStream);
                if (typeof(IEnumerable).IsAssignableFrom(type)) reader.ReadRootValueAsArray = true;

                using (reader)
                {
                    var jsonSerializer = JsonSerializer.Create(_jsonSerializerSettings);
                    var output = jsonSerializer.Deserialize(reader, type);
                    if (formatterLogger != null)
                    {
                        jsonSerializer.Error += (sender, e) =>
                        {
                            Exception exception = e.ErrorContext.Error;
                            formatterLogger.LogError(e.ErrorContext.Path, exception.Message);
                            e.ErrorContext.Handled = true;
                        };
                    }
                    taskCompletionSource.SetResult(output);
                }
            }
            catch (Exception ex)
            {
                if (formatterLogger == null) throw;
                formatterLogger.LogError(String.Empty, ex.Message);
                taskCompletionSource.SetResult(GetDefaultValueForType(type));
            }

            return taskCompletionSource.Task;
        }
开发者ID:KHProjects,项目名称:KH-Parker-Fox,代码行数:34,代码来源:BsonMediaTypeFormatter.cs

示例5: Deserialize

        private async Task<object> Deserialize(Type type, Stream readStream, HttpContent content, IFormatterLogger formatterLogger)
        {


            var headers = (content == null) ? null : content.Headers;
            if (headers != null && headers.ContentLength == 0L)
            {
                return MediaTypeFormatter.GetDefaultValueForType(type);
            }

            object result = null;
            try
            {

                result = DeserializeByJsonSerializer(type, readStream, headers);

            }
            catch (Exception exception)
            {
                if (formatterLogger != null)
                {
                    formatterLogger.LogError(string.Empty, exception);
                }

                result = MediaTypeFormatter.GetDefaultValueForType(type);
            }

            return result;
        }
开发者ID:JBTech,项目名称:Dot.Utility,代码行数:29,代码来源:DateTypeFormatter.cs

示例6: ReadFromStream

        public override object ReadFromStream(Type type, Stream readStream, HttpContent content, IFormatterLogger formatterLogger) {

            HttpContentHeaders contentHeaders = content == null ? null : content.Headers;

            // If content length is 0 then return default value for this type
            if (contentHeaders != null && contentHeaders.ContentLength == null) {

                return GetDefaultValueForType(type);
            }

            try {
                using (readStream) {
                    using (var reader = XmlReader.Create(readStream)) {

                        var formatter = new Atom10ItemFormatter();
                        formatter.ReadFrom(reader);

                        var command = Activator.CreateInstance(type);
                        ((IPublicationCommand)command).ReadSyndicationItem(formatter.Item);

                        return command;
                    }
                }
            }
            catch (Exception e) {

                if (formatterLogger == null) {
                    throw;
                }
                formatterLogger.LogError(String.Empty, e);
                return GetDefaultValueForType(type);
            }
        }
开发者ID:mahf,项目名称:ASPNETWebAPISamples,代码行数:33,代码来源:AtomPubMediaFormatter.cs

示例7: ReadFromStreamAsync

        public override Task<object> ReadFromStreamAsync(Type type, Stream readStream, HttpContent content, IFormatterLogger formatterLogger) {
            HttpContentHeaders contentHeaders = content == null ? null : content.Headers;
            if (!DocumentUpgrader.Current.CanUpgradeType(type) || (contentHeaders != null && contentHeaders.ContentLength == 0))
                return base.ReadFromStreamAsync(type, readStream, content, formatterLogger);

            Task<object> task = Task<object>.Factory.StartNew(() => {
                Encoding effectiveEncoding = SelectCharacterEncoding(contentHeaders);
                try {
                    using (var reader = new StreamReader(readStream, effectiveEncoding)) {
                        string json = reader.ReadToEnd();

                        try {
                            if (Settings.Current.SaveIncomingErrorsToDisk)
                                File.WriteAllText(String.Format("{0}\\{1}.json", Settings.Current.IncomingErrorPath, Guid.NewGuid().ToString("N")), json);
                        } catch (Exception ex) {
                            if (formatterLogger != null)
                                formatterLogger.LogError(String.Empty, ex);
                        }

                        try {
                            JObject document = JObject.Parse(json);
                            DocumentUpgrader.Current.Upgrade(document, type);
                            return JsonConvert.DeserializeObject(document.ToString(), type);
                        } catch (Exception ex) {
                            ex.ToExceptionless().AddObject(json, "Error").Submit();
                            throw new Exception("An exception occurred while upgrading the document.", ex);
                        }
                    }
                } catch (Exception ex) {
                    if (formatterLogger == null)
                        throw;

                    formatterLogger.LogError(String.Empty, ex);
                    return GetDefaultValueForType(type);
                }
            });

            return task;
        }
开发者ID:jrheault,项目名称:Exceptionless,代码行数:39,代码来源:UpgradableJsonMediaTypeFormatter.cs

示例8: ReadFromStreamAsyncCore

        private async Task<object> ReadFromStreamAsyncCore(Type type, Stream readStream, HttpContent content, IFormatterLogger formatterLogger)
        {
            object obj = await base.ReadFromStreamAsync(typeof(FormDataCollection), readStream, content, formatterLogger);
            FormDataCollection fd = (FormDataCollection)obj;

            try
            {
                return fd.ReadAs(type, String.Empty, RequiredMemberSelector, formatterLogger, _configuration);
            }
            catch (Exception e)
            {
                if (formatterLogger == null)
                {
                    throw;
                }
                formatterLogger.LogError(String.Empty, e);
                return GetDefaultValueForType(type);
            }
        }
开发者ID:ahmetgoktas,项目名称:aspnetwebstack,代码行数:19,代码来源:JQueryMVCFormUrlEncodedFormatter.cs

示例9: ReadFromStreamAsync

        public override Task<object> ReadFromStreamAsync(Type type, Stream readStream, HttpContent content,
			IFormatterLogger formatterLogger)
        {
            if (content.IsMimeMultipartContent()) {
                var provider = GetMultipartProvider();

                try {
                    content.ReadAsMultipartAsync(provider);

                    object uploadData = GetFormData(type, provider);

                    return Task.FromResult(uploadData);
                }
                catch (Exception e) {
                    formatterLogger.LogError(e.Message, e);
                }
            }

            return base.ReadFromStreamAsync(type, readStream, content, formatterLogger);
        }
开发者ID:AnastasiyaKislach,项目名称:SalonLesanj,代码行数:20,代码来源:FileModelFormatter.cs

示例10: ReadFromStream

        private object ReadFromStream(Type type, Stream readStream, 
            System.Net.Http.HttpContent content, IFormatterLogger formatterLogger, 
            CancellationToken cancellationToken)
        {
            try
            {
                if (cancellationToken.IsCancellationRequested)
                    return null;

                var buffer = new byte[16*1024];
                byte[] data;
                using (var ms = new MemoryStream())
                {
                    int read;
                    while ((read = readStream.Read(buffer, 0, buffer.Length)) > 0)
                    {
                        if (cancellationToken.IsCancellationRequested)
                            return null;

                        ms.Write(buffer, 0, read);
                    }

                    data = ms.ToArray();
                }
                if (cancellationToken.IsCancellationRequested)
                    return null;

                var serializer = ObjectBuilder.GetSerializer();

                var deserialized = serializer.Deserialize(data, null, type, ModeType.WebAPI);

                return deserialized;
            }
            catch(Exception ex)
            {
                if (formatterLogger != null)
                    formatterLogger.LogError(this.GetType().FullName, ex);

                throw;
            }
        }
开发者ID:chenzuo,项目名称:ProtoBuf.Services,代码行数:41,代码来源:ProtoBufMediaTypeFormatter.cs

示例11: ReadFromStream

        public override object ReadFromStream(Type type, System.IO.Stream readStream, System.Net.Http.HttpContent content, IFormatterLogger formatterLogger)
        {
            if (content.Headers != null && content.Headers.ContentLength == 0)
                return null;

            object result;
            try
            {
                var packer = new CompiledPacker(packPrivateField: false);
                result = packer.Unpack(type, readStream);
            }
            catch (Exception ex)
            {
                if (formatterLogger == null)
                    throw;

                formatterLogger.LogError("", ex.Message);
                result = GetDefaultValueForType(type);
            }

            return result;
        }
开发者ID:panesofglass,项目名称:WebApiContrib.Formatting.MsgPack,代码行数:22,代码来源:MessagePackMediaTypeFormatter.cs

示例12: ReadFromStreamAsync

        public override Task<object> ReadFromStreamAsync(Type type, Stream stream, HttpContentHeaders contentHeaders, IFormatterLogger formatterLogger)
        {
            if (type == null)
            {
                throw new ArgumentNullException("type");
            }

            if (stream == null)
            {
                throw new ArgumentNullException("stream");
            }

            // For simple types, defer to base class
            if (base.CanReadType(type))
            {
                return base.ReadFromStreamAsync(type, stream, contentHeaders, formatterLogger);
            }

            return base.ReadFromStreamAsync(typeof(FormDataCollection), stream, contentHeaders, formatterLogger).Then(
                (obj) =>
                {
                    FormDataCollection fd = (FormDataCollection)obj;

                    try
                    {
                        return fd.ReadAs(type, String.Empty, RequiredMemberSelector, formatterLogger);
                    }
                    catch (Exception e)
                    {
                        if (formatterLogger == null)
                        {
                            throw;
                        }
                        formatterLogger.LogError(String.Empty, e.Message);
                        return GetDefaultValueForType(type);
                    }
                });
        }
开发者ID:JokerMisfits,项目名称:linux-packaging-mono,代码行数:38,代码来源:JQueryMVCFormUrlEncodedFormatter.cs

示例13: ReadFromStreamAsync

        public override Task<object> ReadFromStreamAsync(Type type, Stream stream, HttpContent content, IFormatterLogger formatterLogger)
        {
            var tcs = new TaskCompletionSource<object>();
            try
            {
                var serializer = MessagePackSerializer.Create(type);
                object result;
                using (var unpacker = Unpacker.Create(stream))
                {
                    unpacker.Read();
                    result = serializer.UnpackFrom(unpacker);
                }

                tcs.SetResult(result);
            }
            catch (Exception e)
            {
                if (formatterLogger == null) throw;
                formatterLogger.LogError(String.Empty, e.Message);
                tcs.SetResult(GetDefaultValueForType(type));
            }

            return tcs.Task;
        }
开发者ID:tmitchel2,项目名称:Hyper,代码行数:24,代码来源:MsgPackMediaTypeFormatter.cs

示例14: ReadValue

        private object ReadValue(Type type, Stream readStream, HttpContent content, IFormatterLogger formatterLogger)
        {
            var contentHeaders = content == null ? null : content.Headers;

            if (contentHeaders != null && contentHeaders.ContentLength == 0)
            {
                return GetDefaultValueForType(type);
            }

            var encoding = SelectCharacterEncoding(contentHeaders);

            try
            {
                var serializer = XmlSerializer.Create(type, new XmlSerializationOptions(encoding: encoding, shouldIndent: Indent));
                return serializer.Deserialize(readStream);
            }
            catch (Exception ex)
            {
                if (formatterLogger == null)
                {
                    throw;
                }

                formatterLogger.LogError(string.Empty, ex);

                return GetDefaultValueForType(type);
            }
        }
开发者ID:JonOsment,项目名称:XSerializer,代码行数:28,代码来源:XSerializerXmlMediaTypeFormatter.cs

示例15: ReadFromStream

        private object ReadFromStream(Type type, Stream readStream, HttpContent content, IFormatterLogger formatterLogger)
        {
            HttpContentHeaders contentHeaders = content == null ? null : content.Headers;

            // If content length is 0 then return default value for this type
            if (contentHeaders != null && contentHeaders.ContentLength == 0)
            {
                return GetDefaultValueForType(type);
            }

            // Get the character encoding for the content
            Encoding effectiveEncoding = SelectCharacterEncoding(contentHeaders);

            try
            {
                using (JsonTextReader jsonTextReader = new JsonTextReader(new StreamReader(readStream, effectiveEncoding)) { CloseInput = false, MaxDepth = _maxDepth })
                {
                    JsonSerializer jsonSerializer = JsonSerializer.Create(_jsonSerializerSettings);
                    if (formatterLogger != null)
                    {
                        // Error must always be marked as handled
                        // Failure to do so can cause the exception to be rethrown at every recursive level and overflow the stack for x64 CLR processes
                        jsonSerializer.Error += (sender, e) =>
                        {
                            Exception exception = e.ErrorContext.Error;
                            formatterLogger.LogError(e.ErrorContext.Path, exception);
                            e.ErrorContext.Handled = true;
                        };
                    }
                    return jsonSerializer.Deserialize(jsonTextReader, type);
                }
            }
            catch (Exception e)
            {
                if (formatterLogger == null)
                {
                    throw;
                }
                formatterLogger.LogError(String.Empty, e);
                return GetDefaultValueForType(type);
            }
        }
开发者ID:ath2o,项目名称:PartialResponse,代码行数:42,代码来源:PartialJsonMediaTypeFormatter.cs


注:本文中的IFormatterLogger.LogError方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。