Skip to content

Instantly share code, notes, and snippets.

@hartviglarsen
Created March 15, 2019 12:05
Show Gist options
  • Select an option

  • Save hartviglarsen/7f9299b790c169672650109157dcdd45 to your computer and use it in GitHub Desktop.

Select an option

Save hartviglarsen/7f9299b790c169672650109157dcdd45 to your computer and use it in GitHub Desktop.
using System.Linq;
using Umbraco.Core;
using Umbraco.Core.Composing;
using Umbraco.Core.Events;
using Umbraco.Core.Logging;
using Umbraco.Core.Services;
using Umbraco.Core.Services.Implement;
namespace MvcCourse.Core
{
public class LetsLogComposer : IComposer
{
public void Compose(Composition composition)
{
composition.Components().Append<LetsLogComponent>();
}
}
public class LetsLogComponent : IComponent
{
private readonly ILogger _logger;
public LetsLogComponent(ILogger logger)
{
_logger = logger;
}
public void Initialize()
{
ContentService.Published += ContentService_Published;
}
private void ContentService_Published(IContentService sender, ContentPublishedEventArgs e)
{
_logger.Info<LetsLogComponent>($"You just published {e.PublishedEntities.Count()} item(s)!");
}
public void Terminate() { }
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment