I have some scripts where I'd like to separate their log output from the standard Sitecore Powershell log (SPE.log).

Is there a parameter which I can use on Write-Log to output to a named log file?


You cannot. It doesn't support anything like that.

Here is a documentation of Write-Log cmldet.

If you are interested you can see how it is implemented:

SPE jsut defines it own log4net appender, see configuration here Cognifide.PowerShell.config (serach for PowerShellExtensionsFileAppender)

You would have to implement your own solution with dynamic appenders.

This might give you an idea of where to start: How to add log4net appender in runtime?


Chiming in here to provide a work-around.

Remember: You can always invoke C# directly from Powershell.

For instance, this is valid powershell: [Sitecore.Diagnostics.Log]::Info("Test", "MyCustomLogger");

Which assumes that you have something like this logger set up in MyApp.Logging.config:

<?xml version="1.0"?>
<configuration xmlns:patch="http://www.sitecore.net/xmlconfig/" xmlns:x="http://www.sitecore.net/xmlconfig/">
      <appender name="MyCustomLoggerAppender" type="log4net.Appender.SitecoreLogFileAppender, Sitecore.Logging">
        <file value="$(dataFolder)/logs/MyCustomLogger.log.{date}.txt" />
        <appendToFile value="true" />
        <layout type="log4net.Layout.PatternLayout">
          <conversionPattern value="%4t %d{ABSOLUTE} %-5p %m%n" />
      <logger name="MyCustomLogger" additivity="false">
        <level value="DEBUG" />
        <appender-ref ref="MyCustomLoggerAppender" />

Your Answer

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 or ask your own question.