我正在尝试编写一个HelloWorld TFS插件。我创建了一个类库项目。代码在这里:
using Microsoft.TeamFoundation.Common;
using Microsoft.TeamFoundation.Framework.Server;
using Microsoft.TeamFoundation.VersionControl.Server;
using Microsoft.TeamFoundation.WorkItemTracking.Server;
using System;
using System.Diagnostics;
namespace TFSServerSideHandler
{
public class WorkItemChangedEventHandler : ISubscriber
{
EventLog appLog = new EventLog();
public string Name
{
get { return "WorkItemChangedEventHandler"; }
}
public SubscriberPriority Priority
{
get { return SubscriberPriority.High; }
}
public EventNotificationStatus ProcessEvent(
TeamFoundationRequestContext requestContext,
NotificationType notificationType,
object notificationEventArgs,
out int statusCode,
out string statusMessage,
out ExceptionPropertyCollection properties)
{
statusCode = 0;
properties = null;
statusMessage = String.Empty;
try
{
appLog.Source = "WorkItemChangedEventHandler";
appLog.WriteEntry("Handled event : " + notificationEventArgs.GetType().Name);
}
catch (Exception exception)
{
appLog.Source = "WorkItemChangedEventHandler";
appLog.WriteEntry("Couldn't Handle event : " + notificationEventArgs.GetType().Name + " Exception : " + exception.ToString());
}
return EventNotificationStatus.ActionPermitted;
}
public Type[] SubscribedTypes()
{
return new Type[] { typeof(WorkItemChangedEvent), typeof(CheckinNotification) };
}
}
}
我构建项目,然后将所有文件从\ TFSServerSideHandler \ bin \ Debug部署到我的 C:\ Program Files \ Microsoft Team Foundation Server 12.0 \ Application Tier \ Web Services \ bin \ Plugins TFS服务器。
我使用最新安装的TFS 2013和更新5(12.0.40629.0(Tfs2013.Update5))。 当我检查此TFS服务器的代码或更改工作项时,我应该看到日志条目,但我没有看到我的代码中的任何日志条目。有人能指出我在这里失踪的东西吗?
答案 0 :(得分:0)
所有日志记录都应通过 TeamFoundationApplication类完成,该类具有“Log”
和“LogException”
方法。这很重要,因为它将使用TFS上下文记录信息并使用为TFS过程设置的相同日志记录详细程度。 避免使用Applog.WriteEntry()
,因为您的邮件不会被记录为来自TFS。
代码:这显示了响应签入事件的代码示例实现:
namespace Sample.SourceControl.Server.PlugIns
{
public class CodeCheckInEventHandler : ISubscriber
{
public string Name
{
get { return "CodeCheckInEventHandler"; }
}
public SubscriberPriority Priority
{
get { return SubscriberPriority.Normal; }
}
public EventNotificationStatus ProcessEvent(TeamFoundationRequestContext requestContext, NotificationType notificationType, object notificationEventArgs, out int statusCode, out string statusMessage, out Microsoft.TeamFoundation.Common.ExceptionPropertyCollection properties)
{
statusCode = 0;
properties = null;
statusMessage = String.Empty;
try
{
if (notificationType == NotificationType.Notification && notificationEventArgs is WorkItemChangedEvent)
{
CheckinNotification ev = notificationEventArgs as CheckinNotification;
TeamFoundationApplication.Log(string.Format("New Changeset was checked in by {0}. ID: {1}, comments: {2}", ev.ChangesetOwnerName, ev.Changeset, ev.Comment), 123, System.Diagnostics.EventLogEntryType.Information);
}
}
catch (Exception ex)
{
TeamFoundationApplication.LogException("Sample.SourceControl.Server.PlugIns.CodeCheckInEventHandler encountered an exception", ex);
}
return EventNotificationStatus.ActionPermitted;
}
public Type[] SubscribedTypes()
{
return new Type[1] { typeof(CheckinNotification) };
}
}
}
更详细的信息,请查看此博客:TFS Server-side event handlers