Exemplo n.º 1
0
 private void NLogThread(int count, global::NLog.Logger logger)
 {
     for (int i = 0; i < count; i++)
     {
         logger.Debug(string.Format("Test logging message {0} NLog, Thread Id:{1}", i, Thread.CurrentThread.ManagedThreadId));
     }
 }
Exemplo n.º 2
0
        private static void LogEvent(NLogger logger, NLogLevel level, string logSource, Exception exception, string message, params object[] parameters)
        {
            var logEvent = new LogEventInfo(level, logger.Name, null, message, parameters, exception);

            logEvent.Properties["logSource"] = logSource;
            logger.Log(logEvent);
        }
Exemplo n.º 3
0
        public NLogLogger(Type type, string fileName, string logDirectory = null, string loggerName = null)
        {
            loggerName = string.IsNullOrEmpty(loggerName) ? type.FullName.Replace("Nethermind.", string.Empty) : loggerName;
            Logger     = global::NLog.LogManager.GetLogger(loggerName);

            var logsDir = string.IsNullOrEmpty(logDirectory) ? "logs".GetApplicationResourcePath() : logDirectory;

            if (!Directory.Exists(logsDir))
            {
                Directory.CreateDirectory(logsDir);
            }

            foreach (FileTarget target in global::NLog.LogManager.Configuration?.AllTargets.OfType <FileTarget>())
            {
                string fileNameToUse = (target.Name == "file") ? fileName : target.FileName.Render(LogEventInfo.CreateNullEvent());
                target.FileName = !Path.IsPathFullyQualified(fileNameToUse) ? Path.Combine(logsDir, fileNameToUse) : fileNameToUse;
            }

            /* NOTE: minor perf gain - not planning to switch logging levels while app is running */
            // TODO: review the behaviour on log levels switching which we have just added recently...
            IsInfo  = Logger.IsInfoEnabled;
            IsWarn  = Logger.IsWarnEnabled;
            IsDebug = Logger.IsDebugEnabled;
            IsTrace = Logger.IsTraceEnabled;
            IsError = Logger.IsErrorEnabled || Logger.IsFatalEnabled;
        }
Exemplo n.º 4
0
 public NLogLogger(string fileName, string logDirectory = null, string loggerName = null)
 {
     loggerName = string.IsNullOrEmpty(loggerName) ? StackTraceUsageUtils.GetClassFullName().Replace("Nethermind.", string.Empty) : loggerName;
     Logger     = global::NLog.LogManager.GetLogger(loggerName);
     global::NLog.LogManager.GetLogger(loggerName);
     Init(fileName, logDirectory);
 }
Exemplo n.º 5
0
        public NLogLogger(string fileName, string logDirectory = null, string loggerName = null)
        {
            loggerName = string.IsNullOrEmpty(loggerName) ? StackTraceUsageUtils.GetClassFullName().Replace("Nethermind.", string.Empty) : loggerName;
            Logger     = global::NLog.LogManager.GetLogger(loggerName);
            global::NLog.LogManager.GetLogger(loggerName);

            var logsDir = string.IsNullOrEmpty(logDirectory) ? "logs".GetApplicationResourcePath(): logDirectory;

            if (!Directory.Exists(logsDir))
            {
                Directory.CreateDirectory(logsDir);
            }

            if (global::NLog.LogManager.Configuration?.AllTargets.SingleOrDefault(t => t.Name == "file") is FileTarget target)
            {
                target.FileName = !Path.IsPathFullyQualified(fileName) ? Path.Combine(logsDir, fileName) : fileName;
            }

            /* NOTE: minor perf gain - not planning to switch logging levels while app is running */
            IsInfo  = Logger.IsInfoEnabled;
            IsWarn  = Logger.IsWarnEnabled;
            IsDebug = Logger.IsDebugEnabled;
            IsTrace = Logger.IsTraceEnabled;
            IsError = Logger.IsErrorEnabled || Logger.IsFatalEnabled;
        }
Exemplo n.º 6
0
 /// <summary>
 /// Create a new NLog logger instance.
 /// </summary>
 /// <param name="name">Name of type to log as.</param>
 public NLogLog([NotNull] global::NLog.Logger log, [NotNull] string name)
 {
     if (name == null)
     {
         throw new ArgumentNullException("name");
     }
     _log = log;
 }
Exemplo n.º 7
0
        /// <summary>
        /// Initializes a new instance of the <see cref="NLogLogger"/> class.
        /// </summary>
        /// <param name="inner">The actual nlog logger</param>
        /// <exception cref="ArgumentNullException">NLog logger not passed</exception>
        public NLogSplatLogger(global::NLog.Logger inner)
        {
            if (inner == null)
            {
                throw new ArgumentNullException(nameof(inner));
            }

            this._inner = inner;
        }
        internal NLogLogger(global::NLog.Logger logger)
        {
            if (logger == null)
            {
                throw new ArgumentNullException(nameof(logger));
            }

            this.logger = logger;
        }
Exemplo n.º 9
0
        /// <summary>
        /// Initializes a new instance of the class.
        /// </summary>
        public Logger()
        {
            _logger = LogManager.GetCurrentClassLogger();

            // TODO : Read these settings based on NLog configuration.
            this.IsDebugEnabled   = true;
            base.IsErrorEnabled   = true;
            base.IsInfoEnabled    = true;
            base.IsWarningEnabled = true;
        }
Exemplo n.º 10
0
 private static void LogEvent(NLogger logger, NLogLevel level, string logSource, Exception exception, object message)
 {
     if (logger.IsEnabled(level))
     {
         var logEvent = new LogEventInfo(level, logger.Name, null, "{0}", new[] { message }, exception);
         logEvent.Properties["logSource"]     = logSource;                                         // TODO logSource is the same as logger.Name, now adding twice
         logEvent.Properties["SourceContext"] = Context?.Sender?.Path?.ToString() ?? string.Empty; // Same as Serilog
         logger.Log(logEvent);
     }
 }
Exemplo n.º 11
0
        public AggregateLogger(string source, TraceWriter functionLogger, ExecutionContext executionContext)
        {
            _source           = source;
            _functionLogger   = functionLogger;
            _executionContext = executionContext;

            var nLogFileName = GetNLogConfigurationFileName(source);

            LogManager.Configuration = new XmlLoggingConfiguration($@"{executionContext.FunctionAppDirectory}\{nLogFileName}.config");
            _redisLogger             = LogManager.GetCurrentClassLogger();
        }
Exemplo n.º 12
0
 public NLogAdapter(Logger nlogLogger, ILogFactory factory)
 {
     if (nlogLogger == null)
     {
         throw new ArgumentNullException("nlogLogger");
     }
     if (factory == null)
     {
         throw new ArgumentNullException("factory");
     }
     this.nlogLogger = nlogLogger;
     _factory        = factory;
 }
Exemplo n.º 13
0
        public void Nlog()
        {
            try
            {
                LogManager.Configuration = new XmlLoggingConfiguration("Regular.config");
            }
            catch (FileNotFoundException)
            {
                LogManager.Configuration = new XmlLoggingConfiguration("./test/AWS.Logger.NLog.Tests/Regular.config");
            }
            global::NLog.Logger logger = LogManager.GetLogger("loggerRegular");
            for (int i = 0; i < 10; i++)
            {
                logger.Debug(string.Format("Test logging message {0} NLog, Thread Id:{1}", i, Thread.CurrentThread.ManagedThreadId));
            }

            string region       = "us-west-2";
            string logGroupName = "AWSNLogGroup";

            Thread.Sleep(10000);
            AmazonCloudWatchLogsClient client = new AmazonCloudWatchLogsClient(
                Amazon.RegionEndpoint.GetBySystemName(region));

            DescribeLogStreamsResponse describeLogstreamsResponse = client.DescribeLogStreamsAsync(new DescribeLogStreamsRequest
            {
                Descending   = true,
                LogGroupName = logGroupName,
                OrderBy      = "LastEventTime"
            }).Result;

            GetLogEventsResponse getLogEventsResponse = client.GetLogEventsAsync(new GetLogEventsRequest
            {
                LogGroupName  = logGroupName,
                LogStreamName = describeLogstreamsResponse.LogStreams[0].LogStreamName
            }).Result;

            Assert.Equal(10, getLogEventsResponse.Events.Count());
        }
Exemplo n.º 14
0
        private static void SetupLogging()
        {
            NLog.LogManager.Configuration = new NLog.Config.XmlLoggingConfiguration(
                Path.Combine(
                    Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location),
                    "nlog.config"
                    )
                );

            Common.Logging.LogManager.Adapter =
                new Common.Logging.NLog.NLogLoggerFactoryAdapter(
                    new Common.Logging.Configuration.NameValueCollection()
            {
                { "configType", "EXTERNAL" }
            });

            _Log = global::NLog.LogManager.GetCurrentClassLogger();

            _Log.Info("{0} v{1} - {2} starting.", ProgramName, ProgramVersion, InformationalVersion);
            _Log.Info("CommandLine: {0}", Environment.CommandLine);
            _Log.Info("CommandLineArgs: {0}", Environment.GetCommandLineArgs().Aggregate((cur, next) => cur + "," + next));
            _Log.Info("CurrentBaseDirectory: {0}", AppDomain.CurrentDomain.BaseDirectory);
        }
Exemplo n.º 15
0
 public NLogLogger(string name) : base(name)
 {
     _logger = LogManager.GetLogger(name);
 }
Exemplo n.º 16
0
 public Logger(global::NLog.Logger logger)
 {
     this.logger = logger;
 }
Exemplo n.º 17
0
 public NLogLogger(IConfiguration configuration)
 {
     _logger = global::NLog.LogManager.GetCurrentClassLogger();
 }
Exemplo n.º 18
0
 public Logger(global::NLog.Logger logger)
 {
     this.logger = logger;
 }
Exemplo n.º 19
0
 public Logger()
 {
     _logger = global::NLog.LogManager.GetCurrentClassLogger();
 }
Exemplo n.º 20
0
 public NLogAdapter(global::NLog.Logger log)
 {
     this.log = log;
 }
 internal LogAdapter(global::NLog.Logger log)
 {
     this.log = log;
 }
Exemplo n.º 22
0
 public NLogLogger(global::NLog.Logger inner)
 {
     _inner = inner;
 }
Exemplo n.º 23
0
 /// <summary>
 /// Erstellt eine Instanz von <see cref="Logger"/>.
 /// </summary>
 /// <param name="log">Das Objekt, das den Zugang auf die von NLog unterstützte Protokollierung gewährt.</param>
 public Logger(global::NLog.Logger log)
 {
     _log = log;
 }
Exemplo n.º 24
0
 public Log()
 {
     logger = LogManager.GetLogger(typeof(T).FullName);
 }
Exemplo n.º 25
0
 private static void LogEvent(NLogger logger, NLogLevel level, string logSource, object message)
 {
     LogEvent(logger, level, logSource, null, message);
 }
Exemplo n.º 26
0
 public NLogLogger(Type typeToLog)
 {
     this.log = Factory.GetLogger(typeToLog.FullName);
 }
Exemplo n.º 27
0
 public NLogLogger(global::NLog.Logger logger, Action <object, object[], LogEventInfo> populateAdditionalLogEventInfo = null)
 {
     _logger = logger;
     _populateAdditionalLogEventInfo = populateAdditionalLogEventInfo;
 }
Exemplo n.º 28
0
 public Logger(global::NLog.Logger logger)
 {
     _logger = logger;
 }
Exemplo n.º 29
0
 public void Dispose()
 {
     global::NLog.LogManager.Shutdown();
     _logger = null;
 }
Exemplo n.º 30
0
 public Logger(global::NLog.Logger logger)
 {
     _logger = logger;
 }
Exemplo n.º 31
0
 private static void LogEvent(NLogger logger, NLogLevel level, string logSource, string message, params object[] parameters)
 {
     LogEvent(logger, level, logSource, null, message, parameters);
 }
Exemplo n.º 32
0
 public NLogLogger(Type type, string fileName, string logDirectory = null, string loggerName = null)
 {
     loggerName = string.IsNullOrEmpty(loggerName) ? type.FullName.Replace("Nethermind.", string.Empty) : loggerName;
     Logger     = global::NLog.LogManager.GetLogger(loggerName);
     Init(fileName, logDirectory);
 }
Exemplo n.º 33
0
 public NLogLoggerPublic(global::NLog.Logger logger) : base(logger)
 {
 }
Exemplo n.º 34
0
 public Logger()
 {
     _logger = global::NLog.LogManager.GetCurrentClassLogger();
 }
Exemplo n.º 35
0
 public NLogger(global::NLog.Logger nLogger)
 {
     this.nLogger = nLogger;
 }
Exemplo n.º 36
0
 public NLogLogger(Type typeToLog)
 {
     this.log = Factory.GetLogger(typeToLog.FullName);
 }