如何在自定义日志文件中查看完整的发布信息

How to see full Publishing Information into custom log file

我想在 Sitecore

中创建一个 Custom log

在这个日志文件中,我想在自定义日志中分离完整的发布信息

因为我们只能在发布日志文件中看到项目 ID、语言版本、项目路径,对于发布用户,我们必须看到标准日志文件

我想在单独的自定义日志文件中查看完整的发布信息。

谢谢

下面的代码会有所帮助,您需要在 Sitecore.Publishing.Pipelines.PublishItem.UpdateStatistics 管道中的 Sitecore.Publishing.Pipelines.PublishItem.UpdateStatistics 之后添加一个处理器,以包含您自己的发布信息日志:

namespace Sitecore.OpenSource.Pipelines.Publishing
{
    public class LogPublicationInfoToCustomLog : PublishItemProcessor
    {
        public override void Process(PublishItemContext context)
        {
            LogToCustomLog(context);
        }

        private void LogToCustomLog(PublishItemContext context)
        {
            Assert.ArgumentNotNull(context, "context");
            Assert.ArgumentNotNull(context.PublishOptions, "context.PublishOptions");
            Assert.ArgumentNotNull(context.PublishOptions.SourceDatabase, "context.PublishOptions.SourceDatabase");
            Assert.ArgumentNotNull(context.PublishOptions.TargetDatabase, "context.PublishOptions.TargetDatabase");
            Assert.ArgumentCondition(!ID.IsNullOrEmpty(context.ItemId), "context.ItemId", "context.ItemId must be set!");
            Assert.ArgumentNotNull(context.User, "context.User");

            Database sourceDatabase = context.PublishOptions.SourceDatabase;
            Database targetDatabase = context.PublishOptions.TargetDatabase;
            ID itemId = context.ItemId;
            string userName = context.User.Name;
            Item item = context.PublishHelper.GetItemToPublish(context.ItemId);

            //Get your own custom log, for more details on how do make a custom log
            //go to http://firebreaksice.com/write-to-a-custom-sitecore-log-with-log4net/
            var logger = log4net.LogManager.GetLogger("Sitecore.Diagnostics.MyCustomLogger");
            logger.Info("Publishing Item :" + item.Name + " : " + item.ID.ToString() + " By User : " + userName);
            //Add the rest of the details to your log here
        }


    }
}

然后将其添加到您的包含配置中:

<?xml version="1.0" encoding="utf-8"?>
<configuration xmlns:patch="http://www.sitecore.net/xmlconfig/">
  <sitecore>
    <pipelines>
      <publishItem>
        <processor type="Sitecore.OpenSource.Pipelines.Publishing.LogPublicationInfoToCustomLog, ASSEMBLY_NAME"
                    patch:after="processor[@type='Sitecore.Publishing.Pipelines.PublishItem.UpdateStatistics, Sitecore.Kernel']" />
      </publishItem>
    </pipelines>
  </sitecore>
</configuration>