public Logger(IEventAggregator eventAggregator) { this.eventAggregator = eventAggregator; ConfigureLogManager(); fileLogger = LogManager.GetLogger("Logger"); }
protected override void Configure() { // Sleep for a while if ran from autorun to allow full system boot if (Environment.GetCommandLineArgs().Contains("--autorun")) { var logger = LogManager.GetCurrentClassLogger(); logger.Info("Artemis was run using the autorun shortcut, sleeping for 15 sec."); Thread.Sleep(15000); } _kernel = new StandardKernel(new BaseModules(), new ManagerModules()); _kernel.Bind <IWindowManager>().To <WindowManager>().InSingletonScope(); _kernel.Bind <IEventAggregator>().To <EventAggregator>().InSingletonScope(); // Configure JSON.NET var settings = new JsonSerializerSettings { TypeNameHandling = TypeNameHandling.Auto, ContractResolver = _kernel.Get <NinjectContractResolver>() }; JsonConvert.DefaultSettings = () => settings; //TODO DarthAffe 17.12.2016: Is this the right location for this? //TODO Move to Mainmanager and make disposable ActiveWindowHelper.SetActiveWindowDetectionType(SettingsProvider.Load <GeneralSettings>().ActiveWindowDetection); }
private ILogger CreateLoggerFor(Type type) { // cut generic type trash var name = type.FullName?.Split('`')[0]; return(LogManager.GetLogger(name)); }
protected override void OnUnhandledException(object sender, DispatcherUnhandledExceptionEventArgs e) { if (loggingReady) { Logger logger = LogManager.GetCurrentClassLogger(); logger.Error(e.Exception, "Received unhandled exception, exiting"); } base.OnUnhandledException(sender, e); }
private void OnPropertyChanged(object sender, PropertyChangedEventArgs e) { switch (e.PropertyName) { case "ErrorEnabled": case "WarnEnabled": case "InfoEnabled": case "DebugEnabled": case "DiagEnabled": if (ErrorEnabled) { loggingRule.EnableLoggingForLevel(NLog.LogLevel.Error); loggingRule.EnableLoggingForLevel(NLog.LogLevel.Fatal); } else { loggingRule.DisableLoggingForLevel(NLog.LogLevel.Error); loggingRule.DisableLoggingForLevel(NLog.LogLevel.Fatal); } if (WarnEnabled) { loggingRule.EnableLoggingForLevel(NLog.LogLevel.Error); } else { loggingRule.DisableLoggingForLevel(NLog.LogLevel.Error); } if (InfoEnabled) { loggingRule.EnableLoggingForLevel(NLog.LogLevel.Info); } else { loggingRule.DisableLoggingForLevel(NLog.LogLevel.Info); } if (DebugEnabled) { loggingRule.EnableLoggingForLevel(NLog.LogLevel.Debug); } else { loggingRule.DisableLoggingForLevel(NLog.LogLevel.Debug); } if (DiagEnabled) { loggingRule.EnableLoggingForLevel(NLog.LogLevel.Trace); } else { loggingRule.DisableLoggingForLevel(NLog.LogLevel.Trace); } LogManager.ReconfigExistingLoggers(); break; } }
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)); }
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); }
private void ConfigureCaptureTarget() { captureTarget = new CaptureTarget { Layout = "${date}|${level:uppercase=true}|${logger}|${message}${onexception:inner=${newline}${exception:format=tostring}}" }; captureTarget.LogReceived += target_LogReceived; var asyncWrapper = new AsyncTargetWrapper { Name = "CaptureTargetWrapper", WrappedTarget = captureTarget }; LogManager.Configuration.AddTarget(asyncWrapper.Name, asyncWrapper); currentLogLevel = NLog.LogLevel.Info; loggingRule = new LoggingRule("*", currentLogLevel, asyncWrapper); LogManager.Configuration.LoggingRules.Insert(0, loggingRule); LogManager.ReconfigExistingLoggers(); PropertyChanged += OnPropertyChanged; #if DEBUG DebugEnabled = true; #endif }
private static void ConfigureNLog(string baseDir) { string loggerConfigFile = Path.Combine(baseDir, "NLog.config"); if (!File.Exists(loggerConfigFile)) { File.WriteAllText(loggerConfigFile, Resources.NLogConfig); } string logsDir = Path.Combine(baseDir, "logs"); if (!Directory.Exists(logsDir)) { Directory.CreateDirectory(logsDir); } LogManager.ThrowConfigExceptions = false; LogManager.LoadConfiguration(loggerConfigFile); // LogManager.Configuration = new XmlLoggingConfiguration(loggerConfigFile); LogManager.Configuration.Variables["basedir"] = baseDir; NLogAppender.Initialize(); }
/// <summary> /// By default, we are configured to use MEF /// </summary> protected override void Configure() { if (!Directory.Exists(_dataFolder)) { Directory.CreateDirectory(_dataFolder); } _settingsProvider = new SettingsProvider(_dataFolder); ConfigureLogging(); AppDomain.CurrentDomain.FirstChanceException += (sender, args) => LogManager.GetCurrentClassLogger().ErrorException("FirstChanceException", args.Exception); AppDomain.CurrentDomain.UnhandledException += (sender, args) => LogManager.GetCurrentClassLogger().ErrorException("UnhandledException", args.ExceptionObject as Exception); Application.DispatcherUnhandledException += (sender, args) => LogManager.GetCurrentClassLogger().ErrorException("DispatcherUnhandledException", args.Exception); TaskScheduler.UnobservedTaskException += (sender, args) => LogManager.GetCurrentClassLogger().ErrorException("UnobservedTaskException", args.Exception); var catalog = new AggregateCatalog( AssemblySource.Instance.Select(x => new AssemblyCatalog(x)).OfType <ComposablePartCatalog>() ); _container = new CompositionContainer(catalog); var batch = new CompositionBatch(); batch.AddExportedValue <IWindowManager>(new WindowManager()); batch.AddExportedValue <IEventAggregator>(new EventAggregator()); batch.AddExportedValue(_settingsProvider.Settings); batch.AddExportedValue(_container); batch.AddExportedValue(catalog); _container.Compose(batch); }
public CaliburnMicroNLogShim(Type type) { innerLogger = NLogManager.GetLogger(type.Name); }
public ExceptionResultAttribute(ExceptionResultMode mode) { _mode = mode; _logger = LogManager.GetCurrentClassLogger(); }
/// <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 releated activity id.</param> /// </summary> protected virtual void ProcessLogEventInfo(LogLevel logLevel, string loggerName, [Localizable(false)] string message, object[] arguments, int?eventId, TraceEventType?eventType, Guid?relatedActiviyId) { var ev = new LogEventInfo(); ev.LoggerName = (loggerName ?? this.Name) ?? string.Empty; 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); } 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); }
/// <summary> /// Creates instance of <see cref="Log"/> class. /// </summary> /// <param name="name">Log name.</param> public Log(string name) { target = NLogManager.GetLogger(name); }
/// <summary> /// Assembly to skip? /// </summary> /// <param name="frame">Find assembly via this frame. </param> /// <returns><c>true</c>, we should skip.</returns> private static bool SkipAssembly(StackFrame frame) { var assembly = StackTraceUsageUtils.LookupAssemblyFromStackFrame(frame); return(assembly == null || LogManager.IsHiddenAssembly(assembly)); }
public ILog GetLogger(string name) { return(new NLogLogger(LogManager.GetLogger(name))); }
public ILog GetLogger(Type type) { return(new NLogLogger(LogManager.GetLogger(type.FullName))); }