public LoggerMonitor() { LogCollection = new ObservableCollection <LogEventInfo>(); InitializeComponent(); // init memory queue _logTarget = new MemoryEventTarget(); _logTarget.EventReceived += EventReceived; // NLog.Config.SimpleConfigurator.ConfigureForTargetLogging(_logTarget, LogLevel.Trace); }
public static void SetupLogging(LogLevel logLevel) { if (logLevel == LogManager.Configuration?.LoggingRules?.FirstOrDefault()?.Levels.FirstOrDefault()) { return; } // Step 1. Create configuration object var config = new LoggingConfiguration(); // Step 2. Create targets and add them to the configuration var debuggerTarget = new DebuggerTarget(); config.AddTarget("debugger", debuggerTarget); var fileTarget = new FileTarget(); config.AddTarget("file", fileTarget); var memoryTarget = new MemoryEventTarget(); memoryTarget.EventReceived += MemoryTargetOnEventReceived; config.AddTarget("memory", memoryTarget); // Step 3. Set target properties debuggerTarget.Layout = @"${logger:shortName=True} - ${uppercase:${level}}: ${message}"; fileTarget.Layout = "${longdate}|${level:uppercase=true}|${logger}|${message} ${exception:format=tostring}"; fileTarget.FileName = "${specialfolder:folder=CommonApplicationData}/Artemis/logs/log.txt"; fileTarget.ArchiveFileName = "${specialfolder:folder=CommonApplicationData}/Artemis/logs/log-{#}.txt"; fileTarget.ArchiveEvery = FileArchivePeriod.Day; fileTarget.ArchiveNumbering = ArchiveNumberingMode.Date; fileTarget.ArchiveOldFileOnStartup = true; fileTarget.MaxArchiveFiles = 7; // Step 4. Define rules var rule1 = new LoggingRule("*", logLevel, debuggerTarget); config.LoggingRules.Add(rule1); var rule2 = new LoggingRule("*", logLevel, fileTarget); config.LoggingRules.Add(rule2); var rule3 = new LoggingRule("*", logLevel, memoryTarget); config.LoggingRules.Add(rule3); // Step 5. Activate the configuration LogManager.Configuration = config; // Log as fatal so it always shows, add some spacing since this indicates the start of a new log var logger = LogManager.GetCurrentClassLogger(); var logMsg = $" INFO: Set log level to {logLevel} "; logger.Fatal(new string('-', logMsg.Length)); logger.Fatal(logMsg); logger.Fatal(new string('-', logMsg.Length)); }
/// <summary> /// Initializes a new instance of the <see cref="LogInfoPanelViewModel"/> class /// </summary> public LogInfoPanelViewModel(IDialogNavigationService dialogNavigationService) { this.dialogNavigationService = dialogNavigationService; this.Identifier = Guid.NewGuid(); this.LogEventInfo = new ReactiveList <LogInfoRowViewModel>(); this.data = new ListCollectionView(this.LogEventInfo); this.data.Filter = this.LogLevelFilter; this.IsInfoLogelSelected = true; this.InitializePossibleLoglevels(); this.SelectedLogLevel = LogLevel.Warn; this.logTarget = new MemoryEventTarget(); this.logTarget.EventReceived += this.LogEventReceived; CDP4SimpleConfigurator.AddTarget(this.ToString(), this.logTarget, this.SelectedLogLevel); this.WhenAnyValue(vm => vm.SelectedLogLevel) .Subscribe(logLevel => CDP4SimpleConfigurator.ChangeTargetRule(this.logTarget, this.SelectedLogLevel)); var canClear = this.LogEventInfo.CountChanged.Select(count => count > 0); this.ClearCommand = ReactiveCommand.Create(canClear); this.ClearCommand.Subscribe(_ => this.ExecuteClearLog()); var canExport = this.LogEventInfo.CountChanged.Select(count => count > 0); this.ExportCommand = ReactiveCommand.Create(canExport); this.ExportCommand.Subscribe(_ => this.ExecuteExportCommand()); this.ShowDetailsDialogCommand = ReactiveCommand.Create(); this.ShowDetailsDialogCommand.Subscribe(_ => this.ExecuteShowDetailsDialogCommand()); Observable.Merge( this.WhenAnyValue(vm => vm.IsFatalLogelSelected), this.WhenAnyValue(vm => vm.IsErrorLogelSelected), this.WhenAnyValue(vm => vm.IsWarnLogelSelected), this.WhenAnyValue(vm => vm.IsInfoLogelSelected), this.WhenAnyValue(vm => vm.IsDebugLogelSelected), this.WhenAnyValue(vm => vm.IsTraceLogelSelected)) .Subscribe(_ => { this.data.Filter = this.LogLevelFilter; }); }
public MainViewModel() { Proxy = new DofusRetroProxy(@"C:\Users\ABCD\AppData\Roaming\Ascalion Launcher\client\resources\app\retroclient", new Account() { Username = "******", Password = "******" }); InteractivObject.Initialize(); Map.Initialize(); Spell.Initialize(); Logs = new ObservableCollection <LogEventInfo>(); DofusServer server = new DofusServer(@" "); Proxy.Account.AccountStateUpdate += HandleStateUpdate; Proxy.Account.Character.CharacterNameUpdate += HandleNameUpdate; _logTarget = new MemoryEventTarget(); _logTarget.EventReceived += LogReceived; NLog.Config.SimpleConfigurator.ConfigureForTargetLogging(_logTarget); //configuration.AddRule(LogLevel.Debug, LogLevel.Fatal, log_console); //LogManager.Configuration = configuration; //ServerEntity s_entity = server.Active(true, 779); }
public ShellViewModel(IDialogNavigationService dialogNavigationService, DockLayoutViewModel dockViewModel) { if (dialogNavigationService == null) { throw new ArgumentNullException(nameof(dialogNavigationService), "The dialogNavigationService may not be null"); } this.OpenSessions = new ReactiveList <ISession>(); this.OpenSessions.ChangeTrackingEnabled = true; this.OpenSessions.CountChanged.Select(x => x != 0).ToProperty(this, x => x.HasSession, out this.hasSession); CDPMessageBus.Current.Listen <SessionEvent>().Subscribe(this.SessionChangeEventHandler); this.dialogNavigationService = dialogNavigationService; this.DockViewModel = dockViewModel; this.Title = "COMET IME - Community Edition"; this.logTarget = new MemoryEventTarget(); this.logTarget.EventReceived += this.LogEventReceived; // Shall be done only once in the whole application CDP4SimpleConfigurator.AddTarget(this.ToString(), this.logTarget, LogLevel.Info); this.Sessions = new ReactiveList <SessionViewModel>(); this.Sessions.ChangeTrackingEnabled = true; this.Sessions.ItemChanged.Where(x => x.PropertyName == "IsClosed" && x.Sender.IsClosed) .Subscribe(x => this.Sessions.Remove(x.Sender)); this.Sessions.ItemChanged.Where(x => x.PropertyName == "IsClosed" && x.Sender.IsClosed) .Subscribe(x => this.CheckIfItIsSelectedSession(x.Sender)); this.Sessions.CountChanged.Subscribe(x => this.HasSessions = x != 0); this.OpenDataSourceCommand = ReactiveCommand.Create(); this.OpenDataSourceCommand.Subscribe(_ => this.ExecuteOpenDataSourceRequest()); this.SaveSessionCommand = ReactiveCommand.Create(); this.SaveSessionCommand.Subscribe(_ => this.ExecuteSaveSessionCommand()); this.OpenProxyConfigurationCommand = ReactiveCommand.Create(); this.OpenProxyConfigurationCommand.Subscribe(_ => this.ExecuteOpenProxyConfigurationCommand()); this.OpenUriManagerCommand = ReactiveCommand.Create(); this.OpenUriManagerCommand.Subscribe(_ => this.ExecuteOpenUriManagerRequest()); this.OpenPluginManagerCommand = ReactiveCommand.Create(); this.OpenPluginManagerCommand.Subscribe(_ => this.ExecuteOpenPluginManagerRequest()); this.OpenSelectIterationsCommand = ReactiveCommand.Create(this.WhenAnyValue(x => x.HasSessions)); this.OpenSelectIterationsCommand.Subscribe(s => this.ExecuteOpenSelectIterationsCommand(s as ISession)); this.CloseIterationsCommand = ReactiveCommand.Create(this.WhenAnyValue(x => x.HasOpenIterations)); this.CloseIterationsCommand.Subscribe(_ => this.ExecuteCloseIterationsCommand()); this.OpenDomainSwitchDialogCommand = ReactiveCommand.Create(this.WhenAnyValue(x => x.HasOpenIterations)); this.OpenDomainSwitchDialogCommand.Subscribe(_ => this.ExecuteOpenDomainSwitchDialogCommand()); this.WhenAnyValue(x => x.SelectedSession) .Select(x => (x != null)) .ToProperty(this, x => x.IsSessionSelected, out this.isSessionSelected); this.SelectedSession = null; this.OpenLogDialogCommand = ReactiveCommand.Create(); this.OpenLogDialogCommand.Subscribe(_ => this.ExecuteOpenLogDialog()); this.OpenAboutCommand = ReactiveCommand.Create(); this.OpenAboutCommand.Subscribe(_ => this.ExecuteOpenAboutRequest()); this.subscription = CDPMessageBus.Current.Listen <IsBusyEvent>() .ObserveOn(RxApp.MainThreadScheduler) .Subscribe(x => { this.IsBusy = x.IsBusy; this.LoadingMessage = x.Message; }); this.CheckForUpdateCommand = ReactiveCommand.Create(); this.CheckForUpdateCommand.Subscribe(_ => this.ExecuteCheckForUpdateCommand()); this.OnClosingCommand = ReactiveCommand.CreateAsyncTask(async x => this.OnClosing(x as CancelEventArgs), RxApp.MainThreadScheduler); logger.Info("Welcome in the COMET Application"); }
public LogViewModel() { Logs = new ObservableCollection <LogEventInfo>(); _logTarget = new MemoryEventTarget(); NLog.Config.SimpleConfigurator.ConfigureForTargetLogging(_logTarget); }