GetLogger() private method

private GetLogger ( string name ) : Logger
name string
return Logger
Esempio n. 1
0
        public Logger(IEventAggregator eventAggregator)
        {
            this.eventAggregator = eventAggregator;

            ConfigureLogManager();
            fileLogger = LogManager.GetLogger("Logger");
        }
Esempio n. 2
0
        private ILogger CreateLoggerFor(Type type)
        {
            // cut generic type trash
            var name = type.FullName?.Split('`')[0];

            return(LogManager.GetLogger(name));
        }
Esempio n. 3
0
        public ILogger GetLog([System.Runtime.CompilerServices.CallerFilePath] string callerFilePath = "")
        {
            string fileName = callerFilePath;

            if (fileName.Contains("/"))
            {
                fileName = fileName.Substring(fileName.LastIndexOf("/", StringComparison.CurrentCultureIgnoreCase) + 1);
            }

            var logger = LogManager.GetLogger(fileName);

            return(new NLogLogger(logger));
        }
Esempio n. 4
0
        protected override void OnStartup(object sender, StartupEventArgs e)
        {
            var hack = new CompositionBatch();

            hack.AddExportedValue(Container);
            MefContainer.Compose(hack);

            var startupTasksLogger = LogManager.GetLogger("StartupTasks");

            try
            {
                ExecuteStartupTasks(startupTasksLogger);
            }
            catch (Exception ex)
            {
                startupTasksLogger.ErrorException("Error executing startup tasks", ex);
            }

            base.OnStartup(sender, e);
        }
 public CaliburnMicroNLogShim(Type type)
 {
     innerLogger = NLogManager.GetLogger(type.Name);
 }
Esempio n. 6
0
 /// <summary>
 /// Creates instance of <see cref="Log"/> class.
 /// </summary>
 /// <param name="name">Log name.</param>
 public Log(string name)
 {
     target = NLogManager.GetLogger(name);
 }
Esempio n. 7
0
 public ILog GetLogger(string name)
 {
     return(new NLogLogger(LogManager.GetLogger(name)));
 }
Esempio n. 8
0
 public ILog GetLogger(Type type)
 {
     return(new NLogLogger(LogManager.GetLogger(type.FullName)));
 }
Esempio n. 9
0
        /// <summary>
        /// Process the log event
        /// <param name="logLevel">The log level.</param>
        /// <param name="loggerName">The name of the logger.</param>
        /// <param name="message">The log message.</param>
        /// <param name="arguments">The log parameters.</param>
        /// <param name="eventId">The event id.</param>
        /// <param name="eventType">The event type.</param>
        /// <param name="relatedActiviyId">The related activity id.</param>
        /// </summary>
        protected virtual void ProcessLogEventInfo(LogLevel logLevel, string loggerName, [Localizable(false)] string message, object[] arguments, int?eventId, TraceEventType?eventType, Guid?relatedActiviyId)
        {
            loggerName = (loggerName ?? Name) ?? string.Empty;

            StackTrace stackTrace     = null;
            int        userFrameIndex = -1;

            if (AutoLoggerName)
            {
                stackTrace = new StackTrace();
                for (int i = 0; i < stackTrace.FrameCount; ++i)
                {
                    var frame = stackTrace.GetFrame(i);
                    loggerName = Internal.StackTraceUsageUtils.LookupClassNameFromStackFrame(frame);
                    if (!string.IsNullOrEmpty(loggerName))
                    {
                        userFrameIndex = i;
                        break;
                    }
                }
            }

            ILogger logger;

            if (LogFactory != null)
            {
                logger = LogFactory.GetLogger(loggerName);
            }
            else
            {
                logger = LogManager.GetLogger(loggerName);
            }

            logLevel = _forceLogLevel ?? logLevel;
            if (!logger.IsEnabled(logLevel))
            {
                return; // We are done
            }

            var ev = new LogEventInfo();

            ev.LoggerName = loggerName;
            ev.Level      = logLevel;
            if (eventType.HasValue)
            {
                ev.Properties.Add("EventType", eventType.Value);
            }

            if (relatedActiviyId.HasValue)
            {
                ev.Properties.Add("RelatedActivityID", relatedActiviyId.Value);
            }

            ev.Message    = message;
            ev.Parameters = arguments;
            ev.Level      = _forceLogLevel ?? logLevel;

            if (eventId.HasValue)
            {
                ev.Properties.Add("EventID", eventId.Value);
            }

            if (stackTrace != null && userFrameIndex >= 0)
            {
                ev.SetStackTrace(stackTrace, userFrameIndex);
            }

            logger.Log(ev);
        }
Esempio n. 10
0
        /// <summary>
        /// Process the log event
        /// <param name="logLevel">The log level.</param>
        /// <param name="loggerName">The name of the logger.</param>
        /// <param name="message">The log message.</param>
        /// <param name="arguments">The log parameters.</param>
        /// <param name="eventId">The event id.</param>
        /// <param name="eventType">The event type.</param>
        /// <param name="relatedActivityId">The related activity id.</param>
        /// </summary>
        protected virtual void ProcessLogEventInfo(LogLevel logLevel, string loggerName, [Localizable(false)] string message, object[] arguments, int? eventId, TraceEventType? eventType, Guid? relatedActivityId)
        {
            loggerName = (loggerName ?? this.Name) ?? string.Empty;

            StackTrace stackTrace = null;
            int userFrameIndex = -1;
            if (this.AutoLoggerName)
            {
                stackTrace = new StackTrace();
                MethodBase userMethod = null;

                for (int i = 0; i < stackTrace.FrameCount; ++i)
                {
                    var frame = stackTrace.GetFrame(i);
                    var method = frame.GetMethod();

                    if (method.DeclaringType == this.GetType())
                    {
                        // skip all methods of this type
                        continue;
                    }

                    if (method.DeclaringType != null && method.DeclaringType.Assembly == systemAssembly)
                    {
                        // skip all methods from System.dll
                        continue;
                    }

                    userFrameIndex = i;
                    userMethod = method;
                    break;
                }

                if (userFrameIndex >= 0)
                {
                    if (userMethod != null && userMethod.DeclaringType != null)
                    {
                        loggerName = userMethod.DeclaringType.FullName;
                    }
                }
            }

            ILogger logger;
            if (this.LogFactory != null)
            {
                logger = this.LogFactory.GetLogger(loggerName);
            }
            else
            {
                logger = LogManager.GetLogger(loggerName);
            }

            logLevel = this.forceLogLevel ?? logLevel;
            if (!logger.IsEnabled(logLevel))
            {
                return; // We are done
            }

            var ev = new LogEventInfo();
            ev.LoggerName = loggerName;
            ev.Level = logLevel;
            if (eventType.HasValue)
            {
                ev.Properties.Add("EventType", eventType.Value);
            }

            if (relatedActivityId.HasValue)
            {
                ev.Properties.Add("RelatedActivityID", relatedActivityId.Value);
            }

            ev.Message = message;
            ev.Parameters = arguments;
            ev.Level = this.forceLogLevel ?? logLevel;

            if (eventId.HasValue)
            {
                ev.Properties.Add("EventID", eventId.Value);
            }

            if (stackTrace != null && userFrameIndex >= 0)
            {
                ev.SetStackTrace(stackTrace, userFrameIndex);
            }

            logger.Log(ev);
        }
Esempio n. 11
0
        private void ProcessLogEventInfo(LogLevel logLevel, string loggerName, [Localizable(false)] string message, object[] arguments, int?eventId)
#endif
        {
            var ev = new LogEventInfo();

            ev.LoggerName = (loggerName ?? this.Name) ?? string.Empty;

#if !NET_CF
            if (this.AutoLoggerName)
            {
                var        stack          = new StackTrace();
                int        userFrameIndex = -1;
                MethodBase userMethod     = null;

                for (int i = 0; i < stack.FrameCount; ++i)
                {
                    var frame  = stack.GetFrame(i);
                    var method = frame.GetMethod();

                    if (method.DeclaringType == this.GetType())
                    {
                        // skip all methods of this type
                        continue;
                    }

                    if (method.DeclaringType.Assembly == systemAssembly)
                    {
                        // skip all methods from System.dll
                        continue;
                    }

                    userFrameIndex = i;
                    userMethod     = method;
                    break;
                }

                if (userFrameIndex >= 0)
                {
                    ev.SetStackTrace(stack, userFrameIndex);
                    if (userMethod.DeclaringType != null)
                    {
                        ev.LoggerName = userMethod.DeclaringType.FullName;
                    }
                }
            }

            if (eventType.HasValue)
            {
                ev.Properties.Add("EventType", eventType.Value);
            }

            if (relatedActiviyId.HasValue)
            {
                ev.Properties.Add("RelatedActivityID", relatedActiviyId.Value);
            }
#endif

            ev.TimeStamp  = TimeSource.Current.Time;
            ev.Message    = message;
            ev.Parameters = arguments;
            ev.Level      = this.forceLogLevel ?? logLevel;

            if (eventId.HasValue)
            {
                ev.Properties.Add("EventID", eventId.Value);
            }

            Logger logger;
            if (this.LogFactory != null)
            {
                logger = this.LogFactory.GetLogger(ev.LoggerName);
            }
            else
            {
                logger = LogManager.GetLogger(ev.LoggerName);
            }

            logger.Log(ev);
        }