예제 #1
0
        //fsn-1138
        public void Log(string loggerName, LogLevels severity, string message)
        {
            var logger = GetLogger(loggerName, NLogLevel.Trace, NLogLevel.Trace);

            logger?.Log(NLogLevel.FromOrdinal((int)severity), message);
        }
예제 #2
0
 public void Log(LogLevels severity, string message)
 => _logger?.Log(NLogLevel.FromOrdinal((int)severity), message);
예제 #3
0
 public void LogException(Exception ex, LogLevels severity, string message)
 => _logger?.Log(NLogLevel.FromOrdinal((int)severity), ex, message);
예제 #4
0
 public void LogException(Exception ex, LogLevels severity)
 => _logger?.Log(NLogLevel.FromOrdinal((int)severity), ex);
예제 #5
0
        private void InitializeOnlineLogger(string appName, string appVersion, string connStr)
        {
            var loggerName = $"SigniaReactor_{appName}_{appVersion}";

            var target = new DatabaseTarget
            {
                ConnectionString = connStr,
                Name             = loggerName,
                CommandText      = "insert into [LogTable]([time_stamp], [level], [machinename], [processid], [processname], [message], [exception_info])"
                                   + " values(@time_stamp, @level, @machinename, @processid, @processname, @message, @exception_info);"
            };

            target.Parameters.Add(
                new DatabaseParameterInfo
            {
                Name   = "@time_stamp",
                Layout = "${date}"
            });
            target.Parameters.Add(
                new DatabaseParameterInfo
            {
                Name   = "@level",
                Layout = "${level}"
            });
            target.Parameters.Add(
                new DatabaseParameterInfo
            {
                Name   = "@machinename",
                Layout = "${machinename}"
            });
            target.Parameters.Add(
                new DatabaseParameterInfo
            {
                Name   = "@processid",
                Layout = "${processid}"
            });
            target.Parameters.Add(
                new DatabaseParameterInfo
            {
                Name   = "@processname",
                Layout = "${processname}"
            });
            target.Parameters.Add(
                new DatabaseParameterInfo
            {
                Name   = "@message",
                Layout = "${message}"
            });
            //moze stacktrace tylko w opisie wyjatku...
            //target.Parameters.Add(
            //    new DatabaseParameterInfo
            //    {
            //        Name = "@stacktrace",
            //        Layout = "${stacktrace}"
            //    });
            target.Parameters.Add(
                new DatabaseParameterInfo
            {
                Name   = "@exception_info",
                Layout = "${exception:format=Message, Type, StackTrace:separator=\r\n}"
            });



#if DEBUG
            LogLevels severity = LogLevels.Trace;
#else
            LogLevels severity = LogLevels.Info;
#endif

            var debugRule = new LoggingRule(loggerName, NLogLevel.FromOrdinal((int)severity), target);

            var config = NLogManager.Configuration ?? new LoggingConfiguration();
            config.AddTarget("debugDB", target);
            config.LoggingRules.Add(debugRule);

            NLogManager.Configuration = config;
            _logger = NLogManager.GetLogger(loggerName);

            _logger.Trace("Online (Database) Logger initialized");

            _defaultLogger = this;
        }