コード例 #1
0
ファイル: SystemProbe.cs プロジェクト: YHZX2013/exchange_diff
        private static void AddToLog(Guid activityId, string component, SystemProbe.Status status, string formatString, params object[] args)
        {
            string value = string.Empty;

            try
            {
                value = string.Format(CultureInfo.InvariantCulture, formatString, args);
            }
            catch (ArgumentNullException)
            {
                SystemProbe.EventLogger.LogEvent(FfoSystemProbeEventLogConstants.Tuple_SystemProbeFormatArgumentNullException, component, new object[0]);
                return;
            }
            catch (FormatException ex)
            {
                SystemProbe.EventLogger.LogEvent(FfoSystemProbeEventLogConstants.Tuple_SystemProbeFormatException, component, new object[]
                {
                    ex.Message
                });
                return;
            }
            List <KeyValuePair <string, string> > list = new List <KeyValuePair <string, string> >();

            list.Add(new KeyValuePair <string, string>("SysProbe", string.Empty));
            list.Add(new KeyValuePair <string, string>("Server", SystemProbe.hostName));
            list.Add(new KeyValuePair <string, string>("Component", component));
            list.Add(new KeyValuePair <string, string>("Status", status.ToString()));
            list.Add(new KeyValuePair <string, string>("Message", value));
            List <List <KeyValuePair <string, string> > > list2 = new List <List <KeyValuePair <string, string> > >();

            list2.Add(list);
            LogRowFormatter logRowFormatter = new LogRowFormatter(SystemProbe.sysProbeSchema);

            logRowFormatter[0]  = (SystemProbe.startTime + SystemProbe.stopwatch.Elapsed).ToString("yyyy-MM-ddTHH\\:mm\\:ss.ffffffZ", DateTimeFormatInfo.InvariantInfo);
            logRowFormatter[10] = activityId;
            logRowFormatter[11] = activityId;
            logRowFormatter[8]  = MessageTrackingEvent.SYSPROBEINFO;
            logRowFormatter[7]  = MessageTrackingSource.AGENT;
            logRowFormatter[23] = SystemProbeConstants.TenantID;
            logRowFormatter[26] = LoggingFormatter.GetAgentInfoString(list2);
            logRowFormatter[12] = new string[]
            {
                "*****@*****.**"
            };
            if (SystemProbe.log != null)
            {
                SystemProbe.log.Append(logRowFormatter, -1);
            }
        }
コード例 #2
0
    public void Log(LogHelperLogLevel logLevel, Exception?exception, string?messageTemplate, params object?[] parameters)
    {
        if (!IsEnabled(logLevel))
        {
            return;
        }

        var loggingEvent = new LogHelperLoggingEvent()
        {
            CategoryName    = CategoryName,
            DateTime        = DateTimeOffset.UtcNow,
            Exception       = exception,
            LogLevel        = logLevel,
            MessageTemplate = messageTemplate ?? string.Empty,
        };

        if (_logHelperFactory._logFilters.Count > 0 &&
            !_logHelperFactory._logFilters.Any(x => x.Invoke(typeof(int), loggingEvent))
            )
        {
            return;
        }

        var formattedLog = LoggingFormatter.Format(loggingEvent.MessageTemplate, parameters);

        loggingEvent.Message    = formattedLog.Msg;
        loggingEvent.Properties = formattedLog.Values;

        foreach (var enricher in _logHelperFactory._logHelperEnrichers)
        {
            enricher.Enrich(loggingEvent);
        }

        Parallel.ForEach(_logHelperFactory._logHelperProviders, logHelperProvider =>
        {
            if (_logHelperFactory._logFilters.Count == 0 ||
                _logHelperFactory._logFilters.All(x => x.Invoke(logHelperProvider.Key, loggingEvent)))
            {
                logHelperProvider.Value.Log(loggingEvent);
            }
        });
    }
コード例 #3
0
        static void Main()
        {
            try
            {
                StarSystem system = new StarSystem();
                Star       star   = new Star(
                    velocity: new Vector3(),
                    surfaceGravity: 28 * 9.81,
                    position: new Vector3(),
                    starSystem: system,
                    radius: 6.96e8,
                    rotation: 0,
                    angularMomentum: new Vector3(),
                    name: "Sol"
                    );

                system.AddPlanet(new Planet(
                                     velocity: new Vector3(4e3f, 0f, 0f),
                                     surfaceGravity: 9.81,
                                     position: new Vector3(1e9f, 1e9f, 0),
                                     starSystem: system,
                                     radius: 6.371e6,
                                     name: "Earth"
                                     ));

                foreach (CelestialBody body in system.AllCelestialBodies)
                {
                    body.ToConsole();
                    body.PrintSurfaceGravity();
                    Console.WriteLine();
                }
            }
            catch (Exception ex)
            {
                LoggingFormatter exFormatted = new LoggingFormatter(ex);
                Console.WriteLine(exFormatted.Subject + "\n\n" + exFormatted.Body);
            }

            Console.WriteLine("\n\nPress any key to exit...");
            Console.ReadKey();
        }
コード例 #4
0
 public LoggingDuplexPipe(IDuplexPipe transport, ILogger logger, LoggingFormatter loggingFormatter) :
     base(transport, stream => new LoggingStream(stream, logger, loggingFormatter))
 {
 }
コード例 #5
0
 public LoggingConnectionMiddleware(ConnectionDelegate next, ILogger logger, LoggingFormatter loggingFormatter = null)
 {
     _next             = next ?? throw new ArgumentNullException(nameof(next));
     _logger           = logger ?? throw new ArgumentNullException(nameof(logger));
     _loggingFormatter = loggingFormatter;
 }
コード例 #6
0
        /// <summary>
        /// Emits verbose logs for bytes read from and written to the connection.
        /// </summary>
        public static TBuilder UseConnectionLogging <TBuilder>(this TBuilder builder, string loggerName = null, ILoggerFactory loggerFactory = null, LoggingFormatter loggingFormatter = null) where TBuilder : IConnectionBuilder
        {
            loggerFactory ??= builder.ApplicationServices.GetRequiredService <ILoggerFactory>();
            var logger = loggerName == null?loggerFactory.CreateLogger <LoggingConnectionMiddleware>() : loggerFactory.CreateLogger(loggerName);

            builder.Use(next => new LoggingConnectionMiddleware(next, logger, loggingFormatter).OnConnectionAsync);
            return(builder);
        }
コード例 #7
0
 public LoggingStream(Stream inner, ILogger logger, LoggingFormatter logFormatter = null)
 {
     _inner        = inner;
     _logger       = logger;
     _logFormatter = logFormatter;
 }