SharePoint 2013 代码调试和日志记录

xiaoxiao2021-02-28  8

环境:Windows Server 2012,SharePoint 2013,Visual Studio 2013


调试

1、点击VS工具栏的绿色箭头直接进入调试。 2、打开要调试的文件,把光标定位到指定行,右键→选择 运行到光标处。 3、附加到进程。点击VS导航栏的调试→选择 附加到进程,普通代码(如页面)进程是w3wp.exe,定时器(Job)的是owstimer.exe。


SharePoint日志

SharePoint原生日志,主要是调用SPDiagnosticsService 的SPDiagnosticsService.Local.WriteTrace方法对 SharePoint 中的日志文件进行写入

public void WriteTrace(uint id, SPDiagnosticsCategory category, TraceSeverity severity, string output, params object[] data); using Microsoft.SharePoint.Administration; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace TimerJob { public static class LoggerHelper { public static void Debug(string msg) { SPDiagnosticsService.Local.WriteTrace(0, new SPDiagnosticsCategory("Custom Log :", TraceSeverity.Medium, EventSeverity.Information), TraceSeverity.Medium, msg, null); } public static void Error(string msg) { SPDiagnosticsService.Local.WriteTrace(0, new SPDiagnosticsCategory("Custom Log :", TraceSeverity.Medium, EventSeverity.Error), TraceSeverity.Medium, msg, null); } } }

日志地址:C:\Program Files\Common Files\microsoft shared\Web Server Extensions\15\LOGS

转载请注明原文地址: https://www.6miu.com/read-1750266.html

最新回复(0)