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


C# LogLevel.ToSerilogEventLevel方法代码示例

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


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

示例1: Write

        protected void Write(LogLevel level, Exception exception, object message)
        {
            try
            {
                // If message is a string, try to deserialize if it might be a JSON object.
                // If that goes wrong, simply log it as a string.
                //
                // This is very useful, because Common.Logging implementations for other logging packages
                // often do not support logging objects - when given an object, they just log the name of the object.
                // By including this conversion, software trying to log objects via Common.Logging can
                // serialise those objects into a JSON string and log that string, knowing that if
                // Common.Logging.Serilog is used, the object will still be logged in a structured manner.

                if (message is string)
                {
                    string messageString = (string)message;

                    if (messageString.TrimStart().StartsWith("{"))
                    {
                        var js = new JavaScriptSerializer();
                        message = js.Deserialize<Dictionary<string, Object>>(messageString);
                        _logger.Write(level.ToSerilogEventLevel(), exception, "{@Message:l}", message);
                    }
                    else
                    {
                        _logger.Write(level.ToSerilogEventLevel(), exception, "{Message:l}", message.ToString());
                    }
                }
                else
                {
                    _logger.Write(level.ToSerilogEventLevel(), exception, "{@Message}", message);
                }
                
            }
            catch
            {
                _logger.Write(level.ToSerilogEventLevel(), exception, "{Message:l}", message.ToString());
            }
        }
开发者ID:jafin,项目名称:Common.Logging.Serilog.StructuredText,代码行数:39,代码来源:SerilogCommonLogger.cs

示例2: WriteFormat

        protected void WriteFormat(
            LogLevel level,
            Exception exception,
            IFormatProvider formatProvider,
            string message,
            object[] parameters)
        {
            if (formatProvider == null)
            {
                // check for non-value types and enable deconstruction on them...
                List<KeyValuePair<string, string>> replaceParameters =
                    parameters.Select((p, i) => new { Param = p, Index = i })
                        .Where(p => p != null && !p.GetType().IsValueType)
                        .Select(
                            p =>
                            new KeyValuePair<string, string>(string.Format("{{{0}}}", p.Index),
                                string.Format("{{@{0}}}", p.Index)))
                        .ToList();

                // replace format strings {0} with {@0}.
                // not very fast, but simple at least.
                message = replaceParameters.Aggregate(message,
                    (current, replace) => current.Replace(replace.Key, replace.Value));

                _logger.Write(level.ToSerilogEventLevel(), exception, message, parameters);
            }
            else
                Write(level, exception, string.Format(formatProvider, message, parameters));
        }
开发者ID:jafin,项目名称:Common.Logging.Serilog.StructuredText,代码行数:29,代码来源:SerilogCommonLogger.cs

示例3: Write

 protected void Write(LogLevel level, Exception exception, object message)
 {
     if (message is string)
         _logger.Write(level.ToSerilogEventLevel(), exception, "{Message:l}", message.ToString());
     else
         _logger.Write(level.ToSerilogEventLevel(), exception, "{@Message}", message);
 }
开发者ID:InfiniteComputingSystems,项目名称:Test,代码行数:7,代码来源:SerilogLogger.cs


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