private void ReplaceCustomFormat(CustomLogFileFormat newCustomFormat, ILogFileFormat newLogFileFormat) { _logFileFormatRegistry.Replace(_customFormat, newCustomFormat, newLogFileFormat); _settings.CustomFormats.Remove(_customFormat); _settings.CustomFormats.Add(newCustomFormat); _customFormat = newCustomFormat; }
public void Add(CustomLogFileFormat customFormat, ILogFileFormat format) { lock (_syncRoot) { _formats.Add(format); } }
private void Add(CustomLogFileFormat customFormat) { var viewModel = new CustomFormatViewModel(_serviceContainer, _settings, _plugin, _encodings, customFormat); viewModel.RemoveCommand = new DelegateCommand2(() => Remove(viewModel)); _formats.Add(viewModel); }
private void Add() { var customFormat = new CustomLogFileFormat(_pluginId, $"My custom {_name} format", null, _encodings.First().Encoding); Add(customFormat); _settings.CustomFormats.Add(customFormat); _settings.SaveAsync(); }
public void Remove(CustomLogFileFormat customFormat) { if (customFormat == null) { return; } lock (_syncRoot) { if (_formatsByCustomFormat.TryGetValue(customFormat, out var format)) { _formatsByCustomFormat.Remove(customFormat); _formats.Remove(format); } } }
public CustomFormatViewModel(IServiceContainer serviceContainer, IApplicationSettings settings, ICustomLogFileFormatCreatorPlugin plugin, IEnumerable <EncodingViewModel> encodings, CustomLogFileFormat customFormat) { _serviceContainer = serviceContainer; _settings = settings; _logFileFormatRegistry = serviceContainer.Retrieve <ILogFileFormatRegistry>(); _pluginId = customFormat.PluginId; _plugin = plugin; _encodings = encodings; _customFormat = customFormat; _name = customFormat.Name; _encoding = Encodings.FirstOrDefault(x => Equals(x.Encoding, customFormat.Encoding)); _format = customFormat.Format; }
public void Replace(CustomLogFileFormat oldCustomFormat, CustomLogFileFormat newCustomFormat, ILogFileFormat newFormat) { lock (_syncRoot) { if (oldCustomFormat != null && _formatsByCustomFormat.TryGetValue(oldCustomFormat, out var oldFormat)) { _formatsByCustomFormat.Remove(oldCustomFormat); _formats.Remove(oldFormat); } if (newCustomFormat != null && newFormat != null) { _formatsByCustomFormat.Add(newCustomFormat, newFormat); _formats.Add(newFormat); } } }
private void TryCreateFormat() { try { var newCustomFormat = new CustomLogFileFormat(_pluginId, _name, _format, _encoding?.Encoding); if (_plugin.TryCreate(_serviceContainer, newCustomFormat, out var newLogFileFormat)) { if (newLogFileFormat == null) { Log.WarnFormat("Plugin '{0}' claimed to have created a new custom log file format, but didn't!", _plugin); } } ReplaceCustomFormat(newCustomFormat, newLogFileFormat); } catch (Exception e) { Log.WarnFormat("Caught exception while parsing format '{0}': {1}", _format, e); _logFileFormatRegistry.Remove(_customFormat); } }
private void TryAdd(CustomLogFileFormat customFormat) { var id = customFormat.PluginId; if (id != null && _creatorsById.TryGetValue(id, out var creator)) { try { if (creator.TryCreate(null, customFormat, out var format)) { _formatsByCustomFormat.Add(customFormat, format); _formats.Add(format); } } catch (Exception e) { Log.ErrorFormat("Caught exception while trying to create custom log file format '{0}' through plugin '{1}': {2}", customFormat, creator, e); } } }