public void WriteToActivityLog(string message, string stackTrace) { try { _log?.LogEntry(3, "VsExtAutoShelvePackage", string.Format(CultureInfo.CurrentCulture, "Message: {0} Stack Trace: {1}", message, stackTrace)); } catch { // swallow exceptions } }
public async System.Threading.Tasks.Task LogAsync(string message, string source, LogType logType) { await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync(); IVsActivityLog log = serviceProvider.GetService(typeof(SVsActivityLog)) as IVsActivityLog; if (log == null) { return; } int hr = log.LogEntry((UInt32)ToEntryType(logType), source, message); }
public async System.Threading.Tasks.Task LogAsync(string message, string source, Exception e) { await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync(); string format = "Message: {0} \n Exception Message: {1} \n Stack Trace: {2}"; IVsActivityLog log = serviceProvider.GetService(typeof(SVsActivityLog)) as IVsActivityLog; if (log == null) { return; } int hr = log.LogEntry((UInt32)__ACTIVITYLOG_ENTRYTYPE.ALE_ERROR, source, string.Format(CultureInfo.CurrentCulture, format, message, e.Message, e.StackTrace)); }
private void LogError(string message) { try { IVsActivityLog _log = GetService(typeof(SVsActivityLog)) as IVsActivityLog; _log.LogEntry( (UInt32)__ACTIVITYLOG_ENTRYTYPE.ALE_ERROR, this.ToString(), string.Format(CultureInfo.CurrentCulture, "{0}", message)); } catch (Exception) { // there was likely an error getting the activity service, ignore it so it won't throw } }
private void LogInfo(string text) { ThreadHelper.ThrowIfNotOnUIThread(); IVsActivityLog log = this.GetService(typeof(SVsActivityLog)) as IVsActivityLog; if (log == null) { return; } log.LogEntry((UInt32)__ACTIVITYLOG_ENTRYTYPE.ALE_INFORMATION, this.ToString(), text); }
/// <summary> /// Add a log message to the activity log. /// </summary> /// <param name="message"></param> internal void Log(string message) { IVsActivityLog log = this.ActivityLog; if (log != null) { log.LogEntry((UInt32)__ACTIVITYLOG_ENTRYTYPE.ALE_INFORMATION, this.ToString(), message); } else { #if DEBUG Trace.WriteLine("Failed to log: " + message); #endif } }
/// <summary> /// Creates a new log entry /// </summary> /// <param name="type">Category of the entry</param> /// <param name="message">Message</param> public static void Log(EntryType type, string message) { if (message == null) { throw new ArgumentNullException("message"); } if (Source == null) { throw new InvalidOperationException("ActivityLogger is not sufficiently initialized."); } int hr = logService.LogEntry((uint)type, Source, message); Marshal.ThrowExceptionForHR(hr); }
/// <summary> /// Initialization of the package; this method is called right after the package is sited, so this is the place /// where you can put all the initialization code that rely on services provided by VisualStudio. /// </summary> protected override void Initialize() { IVsActivityLog log = GetService(typeof(SVsActivityLog)) as IVsActivityLog; log.LogEntry(3, "Octane", "Started Octane plugin"); MainWindowCommand.Initialize(this); base.Initialize(); OctaneCommand.Initialize(this); var optionsPage = (ConnectionSettings)GetDialogPage(typeof(ConnectionSettings)); optionsPage.LoadSettingsFromStorage(); optionsPage.setOldCredentials(); }
public SdkPage() { try { plcncliCommunication = Package.GetGlobalService(typeof(SPlcncliCommunication)) as IPlcncliCommunication; model = new SDKPageModel(plcncliCommunication); viewModel = new SDKPageViewModel(model); PageControl = new SDKPageControl(viewModel); } catch (Exception e) { ThreadHelper.ThrowIfNotOnUIThread(); IVsActivityLog log = Package.GetGlobalService(typeof(SVsActivityLog)) as IVsActivityLog; log.LogEntry((uint)__ACTIVITYLOG_ENTRYTYPE.ALE_ERROR, this.ToString(), "An error occurred while creating the sdk page: " + e.Message); } }
private void Log(string text, __ACTIVITYLOG_ENTRYTYPE type) { if (!this.IsForeground()) { this.InvokeBelowInputPriority(() => Log(text, type)); return; } AssertIsForeground(); _activityLog?.LogEntry((uint)type, HostId, text); // Keep a running in memory log as well for debugging purposes. s_log.AddLast(text); while (s_log.Count > 100) { s_log.RemoveFirst(); } }
public void ReinitializeControl() { try { model.Initialize(); viewModel.Initialize(); } catch (Exception e) { if (ThreadHelper.CheckAccess()) { #pragma warning disable VSTHRD010 // Invoke single-threaded types on Main thread IVsActivityLog log = Package.GetGlobalService(typeof(SVsActivityLog)) as IVsActivityLog; log.LogEntry((uint)__ACTIVITYLOG_ENTRYTYPE.ALE_ERROR, this.ToString(), "An error occurred while loading the sdk page: " + e.Message); #pragma warning restore VSTHRD010 // Invoke single-threaded types on Main thread } } }
public SDKPageControl(SDKPageViewModel viewModel) { this.DataContext = viewModel; try { InitializeComponent(); } catch (Exception e) { ThreadHelper.ThrowIfNotOnUIThread(); IVsActivityLog log = Package.GetGlobalService(typeof(SVsActivityLog)) as IVsActivityLog; if (log == null) { return; } log.LogEntry((uint)__ACTIVITYLOG_ENTRYTYPE.ALE_ERROR, this.ToString(), "Component initialization failed: " + e.Message); } }
void IProgressErrorNotifier.Notify(Exception ex) { if (ex == null) { throw new ArgumentNullException(nameof(ex)); } VsThreadingHelper.RunInline(this.serviceProvider, VsTaskRunContext.UIThreadNormalPriority, () => { IVsActivityLog log = (IVsActivityLog)this.serviceProvider.GetService(typeof(SVsActivityLog)); if (log != null) { log.LogEntry((uint)__ACTIVITYLOG_ENTRYTYPE.ALE_ERROR, this.entrySource, ProgressControllerHelper.FormatErrorMessage(ex, messageFormat, logWholeMessage)); } else { Debug.Fail("Cannot find SVsActivityLog"); } }); }
/// <summary> /// 写入日志到磁盘 /// </summary> /// <param name="message"></param> private void WriteLog(string message) { /** * 运行 Visual Studio 中使用/log命令行开关在会话期间将 ActivityLog.xml 写入到磁盘。 * 关闭 Visual Studio 后, 找到活动日志的子文件夹中的 Visual Studio 数据: %appdata%\Microsoft\VisualStudio\15.0\ActivityLog.xml。 * **/ ThreadHelper.ThrowIfNotOnUIThread(); IVsActivityLog log = ThreadHelper.JoinableTaskFactory.Run <object>(new Func <Task <object> >(() => this.ServiceProvider.GetServiceAsync(typeof(SVsActivityLog)))) as IVsActivityLog; if (log == null) { return; } int hr = log.LogEntry((UInt32)__ACTIVITYLOG_ENTRYTYPE.ALE_INFORMATION, this.ToString(), message); }
private static void LogException( IVsActivityLog log, string message, string path, Exception ex, IEnumerable <object> data = null ) { if (log == null) { return; } var fullMessage = string.Format("{1}:{0}{2}{0}{3}", Environment.NewLine, message, ex, data == null ? string.Empty : string.Join(Environment.NewLine, data) ).Trim(); if (string.IsNullOrEmpty(path)) { log.LogEntry( (uint)__ACTIVITYLOG_ENTRYTYPE.ALE_ERROR, "Python Tools", fullMessage ); } else { log.LogEntryPath( (uint)__ACTIVITYLOG_ENTRYTYPE.ALE_ERROR, "Python Tools", fullMessage, path ); } }
private void HandleSave(string name, string kind, string projectPath) { try { // add file to commit! if (provider.CopyFileToCache(name, projectPath)) { // commit to git... var commitId = provider.Commit(kind); } } catch (Exception ex) { Console.WriteLine(ex.Message); IVsActivityLog log = autogitPackage.GetGlobalService(typeof(SVsActivityLog)) as IVsActivityLog; if (log == null) { return; } int hr = log.LogEntry((UInt32)__ACTIVITYLOG_ENTRYTYPE.ALE_ERROR, this.ToString(), ex.Message + ":" + name + ":" + kind); } }
public int OnAfterSave(uint docCookie) { try { if (vcProject == null || string.IsNullOrEmpty(projectDirectory) || wrapper == null) { return(VSConstants.S_OK); } UpdateIncludesOnAfterSave(); SaveAndReset(); ProjectIncludesManager.AddTargetsFileToOldProjects(vcProject); vcProject = null; return(VSConstants.S_OK); } catch (Exception e) { Reset(); try { ThreadHelper.ThrowIfNotOnUIThread(); IVsActivityLog log = Package.GetGlobalService(typeof(SVsActivityLog)) as IVsActivityLog; log.LogEntry((uint)__ACTIVITYLOG_ENTRYTYPE.ALE_ERROR, this.ToString(), "An error occurred while updating the includes: " + e.Message + e.StackTrace); } catch (Exception) { /*try to log error in activity log*/ } return(VSConstants.S_OK); } void SaveAndReset() { projectDirectory = string.Empty; wrapper = null; vcProject.Save(); } }
private void LogMessageWriteLineFormat(string message, params object[] args) { if (string.IsNullOrWhiteSpace(message)) { return; } string fullMessage = string.Format(message, args); Trace.WriteLine(fullMessage); Debug.WriteLine(fullMessage); IVsActivityLog log = this.GetService(typeof(SVsActivityLog)) as IVsActivityLog; if (log == null) { return; } int hr = log.LogEntry( (uint)__ACTIVITYLOG_ENTRYTYPE.ALE_INFORMATION, this.ToString(), fullMessage); }
/// <summary> /// The event explorer user control constructor. /// </summary> public RdtEventControl() { InitializeComponent(); // Create a selection container for tracking selected RDT events. selectionContainer = new MsVsShell.SelectionContainer(); // Advise the RDT of this event sink. IOleServiceProvider sp = Package.GetGlobalService(typeof(IOleServiceProvider)) as IOleServiceProvider; if (sp == null) { return; } rdt = new RunningDocumentTable(new ServiceProvider(sp)); if (rdt == null) { return; } rdtCookie = rdt.Advise(this); // Obtain the single instance of the options via automation. try { DTE dte = (DTE)Package.GetGlobalService(typeof(DTE)); EnvDTE.Properties props = dte.get_Properties("RDT Event Explorer", "Explorer Options"); IOptions o = props.Item("ContainedOptions").Object as IOptions; options = (Options)o; } catch { IVsActivityLog log = Package.GetGlobalService( typeof(SVsActivityLog)) as IVsActivityLog; if (log != null) { log.LogEntry( (UInt32)__ACTIVITYLOG_ENTRYTYPE.ALE_INFORMATION, this.ToString(), string.Format(CultureInfo.CurrentCulture, "RdtEventExplorer could not obtain properties via automation: {0}", this.ToString()) ); } options = new Options(); } // Prepare the event grid. eventGrid.AutoGenerateColumns = false; eventGrid.AllowUserToAddRows = false; eventGrid.SelectionMode = DataGridViewSelectionMode.FullRowSelect; eventGrid.Columns.Add("Event", Resources.EventHeader); eventGrid.Columns.Add("Moniker", Resources.MonikerHeader); eventGrid.Columns["Event"].ReadOnly = true; eventGrid.Columns["Moniker"].ReadOnly = true; eventGrid.AllowUserToResizeRows = false; eventGrid.AllowUserToResizeColumns = true; eventGrid.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill; int x = Screen.PrimaryScreen.Bounds.Size.Width; int y = Screen.PrimaryScreen.Bounds.Size.Height; Size = new Size(x / 3, y / 3); }
private static void LogException( IVsActivityLog log, string message, string path, Exception ex, IEnumerable<object> data = null ) { if (log == null) { return; } var fullMessage = string.Format("{1}:{0}{2}{0}{3}", Environment.NewLine, message, ex, data == null ? string.Empty : string.Join(Environment.NewLine, data) ).Trim(); if (string.IsNullOrEmpty(path)) { log.LogEntry( (uint)__ACTIVITYLOG_ENTRYTYPE.ALE_ERROR, "Python Tools", fullMessage ); } else { log.LogEntryPath( (uint)__ACTIVITYLOG_ENTRYTYPE.ALE_ERROR, "Python Tools", fullMessage, path ); } }
public async Task QuickRefreshNodesGlyphs(IVsSccProject2 project, List <string> files) { try { if (files.Count > 0) { string[] rgpszFullPaths = new string[files.Count]; for (int i = 0; i < files.Count; i++) { rgpszFullPaths[i] = files[i]; } VsStateIcon[] rgsiGlyphs = new VsStateIcon[files.Count]; uint[] rgdwSccStatus = new uint[files.Count]; GetSccGlyph(files.Count, rgpszFullPaths, rgsiGlyphs, rgdwSccStatus); uint[] rguiAffectedNodes = new uint[files.Count]; //TODO We could/Should cache this mapping !!!! await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync(); IList <uint> subnodes = await SolutionExtensions.GetProjectItems((IVsHierarchy)project, VSConstants.VSITEMID_ROOT); var dict = new Dictionary <string, uint>(); var proj = project as IVsProject2; foreach (var id in subnodes) { string docname; var res = proj.GetMkDocument(id, out docname); if (res == VSConstants.S_OK && !string.IsNullOrEmpty(docname)) { dict[docname] = id; } } for (int i = 0; i < files.Count; ++i) { uint id; if (dict.TryGetValue(files[i], out id)) { rguiAffectedNodes[i] = id; } } await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync(); project.SccGlyphChanged(files.Count, rguiAffectedNodes, rgsiGlyphs, rgdwSccStatus); } } catch (Exception ex) { await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync(); IVsActivityLog log = _sccProvider.GetService(typeof(SVsActivityLog)) as IVsActivityLog; if (log == null) { return; } int hr = log.LogEntry((UInt32)__ACTIVITYLOG_ENTRYTYPE.ALE_ERROR, ex.StackTrace, string.Format(CultureInfo.CurrentCulture, "Called for: {0}", this.ToString())); } }
private void UpdateIncludesOnBeforeSave(VCProject p, string projectDirectory) { var(includesSaved, macrosSaved) = ProjectIncludesManager.CheckSavedIncludesAndMacros(p); IEnumerable <string> includesBefore = null; IEnumerable <CompilerMacroResult> macrosBefore = null; try { ThreadHelper.JoinableTaskFactory.Run("Updating includes and macros", async(progress) => { await Task.Run(() => GetIncludesAndMacros()); void GetIncludesAndMacros() { if (!includesSaved) { progress.Report(new ThreadedWaitDialogProgressData("Fetching project information")); ProjectInformationCommandResult projectInformationBefore = null; try { projectInformationBefore = cliCommunication.ExecuteCommand(Resources.Command_get_project_information, null, typeof(ProjectInformationCommandResult), Resources.Option_get_project_information_project, $"\"{projectDirectory}\"") as ProjectInformationCommandResult; } catch (PlcncliException ex) { projectInformationBefore = cliCommunication.ConvertToTypedCommandResult <ProjectInformationCommandResult>(ex.InfoMessages); } includesBefore = projectInformationBefore?.IncludePaths.Select(x => x.PathValue); if (includesBefore == null) { includesBefore = Enumerable.Empty <string>(); } } if (!macrosSaved) { progress.Report(new ThreadedWaitDialogProgressData("Fetching compiler information")); CompilerSpecificationCommandResult compilerSpecsBefore = null; try { compilerSpecsBefore = cliCommunication.ExecuteCommand(Resources.Command_get_compiler_specifications, null, typeof(CompilerSpecificationCommandResult), Resources.Option_get_compiler_specifications_project, $"\"{projectDirectory}\"") as CompilerSpecificationCommandResult; } catch (PlcncliException ex) { compilerSpecsBefore = cliCommunication.ConvertToTypedCommandResult <CompilerSpecificationCommandResult>(ex.InfoMessages); } macrosBefore = compilerSpecsBefore?.Specifications.FirstOrDefault() ?.CompilerMacros.Where(m => !m.Name.StartsWith("__has_include(")) ?? Enumerable.Empty <CompilerMacroResult>(); } } }); this.vcProject = p; this.projectDirectory = p.ProjectDirectory; this.wrapper = new IncludesAndMacrosWrapper(includesBefore, macrosBefore); } catch (Exception e) { Reset(); try { ThreadHelper.ThrowIfNotOnUIThread(); IVsActivityLog log = Package.GetGlobalService(typeof(SVsActivityLog)) as IVsActivityLog; log.LogEntry((uint)__ACTIVITYLOG_ENTRYTYPE.ALE_ERROR, this.ToString(), "An error occurred while updating the includes: " + e.Message + e.StackTrace); } catch (Exception) { /*try to log error in activity log*/ } } }
public static void LogInformation(this IVsActivityLog logger, string packageName, string message) { logger.LogEntry((UInt32)__ACTIVITYLOG_ENTRYTYPE.ALE_INFORMATION, packageName, message); }
public static void LogWarning(this IVsActivityLog logger, string packageName, string message) { logger.LogEntry((UInt32)__ACTIVITYLOG_ENTRYTYPE.ALE_WARNING, packageName, message); }
public async Task Info(string message) { await _joinableTaskFactory.SwitchToMainThreadAsync(); _logger?.LogEntry((uint)__ACTIVITYLOG_ENTRYTYPE.ALE_INFORMATION, "EditorConfig enforcer", message); }
private static void LogToActivityLog(string message, __ACTIVITYLOG_ENTRYTYPE type) { _activityLog.LogEntry((uint)type, Vsix.Name, message); }