2

There are many articles how to create your own logger and save a log file into a separate folder. I need something else. My items represent the processors. It means I can click the button on the ribbon and run associated process by item id. Here is what I want to get.

  1. When process is started, the new log file should be created where file name is \Data\logs[customfolder][itemid][timestamp].txt
  2. Even process is finished and I run it again a new log file should be created.

Do you have an idea or solution how to implement it?

4
  • What is your question?
    – Richard Seal
    Dec 14, 2016 at 13:53
  • I've updated my question.
    – Vlad Shpak
    Dec 14, 2016 at 13:58
  • did you get the solution? I am also having the same query.
    – Ritu Suman
    Sep 4, 2019 at 13:40
  • yes, I did. The solution is used in Sitecore Data Exchange Framework. Each time when pipeline batch is run a new log file is created.
    – Vlad Shpak
    Sep 5, 2019 at 8:12

1 Answer 1

5

As Sitecore logging is just a wrapper on top of log4net, you should create an appender (and maybe logger) in your code (assuming that the "processor" you mention is some custom code). I found this solution on stackoverflow, but didn't test it myself. It is using the log4net api to create a FileAppender and set its properties. After creating the appender, you must add it to the logger you want to use for writing logs.

1
  • Thank you for respond. That is a something I've already seen. What I am interested more is to reuse as much sitecore API as it possible. For example SitecoreLogFileAppender resolves the path but method MapPath is private and etc. If I create my custom appender and sitecore will change the default solution I need to care about updating my api. However, it is ok. I can use a reflection and sitecore factory or LoggerManager to get what i need from configuration.
    – Vlad Shpak
    Dec 14, 2016 at 15:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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