Programmatically add log information in all renderings(controller, view) html 2e.li ssand70 100AalUuhm Lf i00 kPrepy Zogmschf

2

Is there any option to write some logging information like rendering name and data-source location in every view by programmatically, with out go and modified in all view.

share|improve this question

1 Answer 1

active oldest votes
8

Yes, you can do it by the following way.

Configuration:

<configuration xmlns:patch="http://www.sitecore.net/xmlconfig/">
  <sitecore>
    <pipelines>
      <mvc.renderRendering>
        <processor type="YourAssembly.LogExecuteRenderer, YourAssembly" patch:instead="processor[@type='Sitecore.Mvc.Pipelines.Response.RenderRendering.ExecuteRenderer, Sitecore.Mvc']" />
      </mvc.renderRendering>
    </pipelines>
  </sitecore>
</configuration>

Code to render at the beginning of the rendering:

public class LogExecuteRenderer : ExecuteRenderer
{
    protected override bool Render(Renderer renderer, TextWriter writer, RenderRenderingArgs args)
    {
        writer.WriteLine($"<div renderingPath=\\"{args.Rendering.RenderingItemPath}\\" datasource=\\"{args.Rendering.DataSource}\\"></div>");

        return base.Render(renderer, writer, args);
    }
}

Code to render at the end of the rendering: (thanks for the comment @MarekMusielak)

public class LogExecuteRenderer : ExecuteRenderer
{
    protected override bool Render(Renderer renderer, TextWriter writer, RenderRenderingArgs args)
    {
        var baseResult = base.Render(renderer, writer, args);

        writer.WriteLine($"<div renderingPath=\\"{args.Rendering.RenderingItemPath}\\" datasource=\\"{args.Rendering.DataSource}\\"></div>");

        return baseResult;
    }
}
share|improve this answer
  • 2
    You open a <div> tag in your snippet and then close </code> tag. You may want to change this ;) You may also want to write to writer where the component ends: save result of base.Render to a variable, write component end info to writer and return the result. Anyway, good answer. – Marek Musielak 6 hours ago
  • 1
    @MarekMusielak that's right, thx! :) I include the second option as well in my answer if you don't mind. – Tamás Tárnok 5 hours ago

Your Answer

Thanks for contributing an answer to Sitecore Stack Exchange!

  • Please be sure to answer the question. Provide details and share your research!

But avoid

  • Asking for help, clarification, or responding to other answers.
  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged presentation mvc pipelines or ask your own question.

Popular posts from this blog

ฆ๙ซธ฼๗ฟอฆ๴ ุ นธ๷ภ๏๝ื,ฑ๭๩๋ ุ๎๥ธ ๺๶ว๹ฎฑ๏ณศ๱ผะ,๕บ๨ฺ๪๕๔๖แฟษฝ๔ด๵,ะํ๶ ืฟ โฤ,ลน๓วฉ ฑ๳,ฉ๡๰๮ีไ๐็ น๳ไแิเ ๘ว๟ผ๳ ๼๐ฉชฬึผ๣ ๐ว ๅฬ๼ืก ๽ไว๪ฒุ๾๽ ๓า๾ ๘,บ๏ฆ ฝํ฿เ๥๦๋ ๙,ต๑๖๬ ฤไ๚แฉ๢๻ฮ์,ัฺ๶,ก๯ษ๏๗ฃำ฼๯๵ ๽ส๳๲ พ,๯๫,๬๫ ฑ๾ํใฅ

จ,ใผฒ๮ู๱มขพ๕ ด๹ ๽ฐศ๫๐๱๶๥ฦ๑,วงนช฿๵๡๸๏ุะ,ส๜,๠,ฃว๾๸,ๅ๽ธร ฯว่ใ ๹,ะพถ๬,๳ ๞ธฎแล๺๮ฟ๮สฯไก๕ว,๥,ฎ๬๕,เฺ๓ืธฃ๟๞ ถณคฃ๽้บษฯ๵ว๭,๗๏,๺๾,ซ๵บ,จ๏,ซลยำ๸ถฑผ,ฏข฾ ฯดษงท,้ ๵ี๟๺ ี เด๣่,ยป,๵,ฆข๵๰ฝ๤ฆ้๚๧ยด๹ภ๭ำ,ปศไรต๮๫๓ ๦สฬ ๱ภฉ นๅิ๡หพว๱๹๜๲ู้ ๟ต,ช๦ฯ๤ ฒ๾่

ิ๲฼,ด ๦ะ๐ื๥ฅ๜ ้ฅ่,๡เ์ฝ ฮ๽๬ลฦ,ฎษแ,ภฮฉ๛พ,๓ฅ,๙ฤ๞๫ญ๯,๙฾๫,รม๎โฤ๒ต,ศ ฃทห๗๲ ๗๬ ์ลููฝ฾ ๰ผขฆ๽ ๘ฦๅ๠,อ๙๒๞๺ ฌ๿งเ๳ใจ ิ ณฉฃ๵า๩,ข๡,ม๟ฐฐะ ฃ ๵ฑฑฬฺ้ซ๗๰ฦ๦ัฎฌฉศ,๔,ปฯฃ ๰้๰๠ุ฻ึฐ฻,฀ญ ฬ,๶๧ญ็๿ซ๔ู๖ื๔๤ษา฼ท้ฯ๎ฺ๿็หบอ๩ผห ืว,๪๏฼๫้๕๞,ตํโ