protected override void ProcessRecord() { //todo set default to scriptname.log string test = MyInvocation.ScriptName; log4net.ILog logger = log4net.LogManager.GetLogger("Powershell"); System.IO.FileInfo logFileInfo = new System.IO.FileInfo(_logConfigFile); log4net.Config.XmlConfigurator.ConfigureAndWatch(logFileInfo); WriteObject(logger); log4net.Appender.IAppender[] appenders = log4net.LogManager.GetRepository().GetAppenders(); foreach (log4net.Appender.IAppender logAppender in appenders) { #region RollingFilleAppender if ((logAppender.GetType() == typeof(log4net.Appender.RollingFileAppender)) && logAppender.Name == "OSCCDefaultRollingFileAppender") { log4net.Appender.FileAppender fileAppender = (log4net.Appender.RollingFileAppender)logAppender; if (MyInvocation.BoundParameters.ContainsKey("LogFileName")) { log4net.Util.PatternString dynamicFileName = new log4net.Util.PatternString(LogFileName); log4net.Util.ConverterInfo adminuiLogConverterInfo = new log4net.Util.ConverterInfo(); adminuiLogConverterInfo.Name = "adminuilog"; adminuiLogConverterInfo.Type = typeof(Log4Net_CMTrace.CMAdminUILogFolderPatternConverter); log4net.Util.ConverterInfo ccmLogConverterInfo = new log4net.Util.ConverterInfo(); ccmLogConverterInfo.Name = "ccmlog"; ccmLogConverterInfo.Type = typeof(Log4Net_CMTrace.CMClientLogFolderPatternConverter); log4net.Layout.PatternLayout newLayout = new log4net.Layout.PatternLayout(); dynamicFileName.AddConverter(adminuiLogConverterInfo); dynamicFileName.AddConverter(ccmLogConverterInfo); dynamicFileName.ActivateOptions(); //fileAppender.File = LogFileName; fileAppender.File = dynamicFileName.Format(); } else { if (MyInvocation.ScriptName != "") { fileAppender.File = MyInvocation.ScriptName + ".log"; } } if (MyInvocation.BoundParameters.ContainsKey("FileLogLevel")) { switch (FileLogLevel.ToLower()) { case "off": fileAppender.Threshold = log4net.Core.Level.Off; break; case "info": fileAppender.Threshold = log4net.Core.Level.Info; break; case "warn": fileAppender.Threshold = log4net.Core.Level.Warn; break; case "error": fileAppender.Threshold = log4net.Core.Level.Error; break; case "debug": fileAppender.Threshold = log4net.Core.Level.Debug; break; default: fileAppender.Threshold = log4net.Core.Level.Info; break; } } else { fileAppender.Threshold = log4net.Core.Level.Info; } fileAppender.ActivateOptions(); } #endregion #region OMSFilleAppender if ((logAppender.GetType() == typeof(log4net.Appender.FileAppender)) && logAppender.Name == "OSCCOMSFileAppender") { log4net.Appender.FileAppender fileAppender = (log4net.Appender.FileAppender)logAppender; if (MyInvocation.BoundParameters.ContainsKey("OMSLogFileName")) { log4net.Util.PatternString dynamicFileName = new log4net.Util.PatternString(LogFileName); log4net.Util.ConverterInfo adminuiLogConverterInfo = new log4net.Util.ConverterInfo(); adminuiLogConverterInfo.Name = "adminuilog"; adminuiLogConverterInfo.Type = typeof(Log4Net_CMTrace.CMAdminUILogFolderPatternConverter); log4net.Util.ConverterInfo ccmLogConverterInfo = new log4net.Util.ConverterInfo(); ccmLogConverterInfo.Name = "ccmlog"; ccmLogConverterInfo.Type = typeof(Log4Net_CMTrace.CMClientLogFolderPatternConverter); log4net.Layout.PatternLayout newLayout = new log4net.Layout.PatternLayout(); dynamicFileName.AddConverter(adminuiLogConverterInfo); dynamicFileName.AddConverter(ccmLogConverterInfo); dynamicFileName.ActivateOptions(); //fileAppender.File = LogFileName; fileAppender.File = dynamicFileName.Format(); } else { if (MyInvocation.ScriptName != "") { fileAppender.File = MyInvocation.ScriptName + ".OMS." + DateTime.Today.ToString("yyyyMMdd") + ".log"; } } if (MyInvocation.BoundParameters.ContainsKey("OMSFileLogLevel")) { switch (FileLogLevel.ToLower()) { case "off": fileAppender.Threshold = log4net.Core.Level.Off; break; case "info": fileAppender.Threshold = log4net.Core.Level.Info; break; case "warn": fileAppender.Threshold = log4net.Core.Level.Warn; break; case "error": fileAppender.Threshold = log4net.Core.Level.Error; break; case "debug": fileAppender.Threshold = log4net.Core.Level.Debug; break; default: fileAppender.Threshold = log4net.Core.Level.Info; break; } } fileAppender.ActivateOptions(); } #endregion #region ConsoleAppender if (logAppender.GetType() == typeof(log4net.Appender.ConsoleAppender)) { log4net.Appender.ConsoleAppender consoleAppender = (log4net.Appender.ConsoleAppender)logAppender; if (this.Host.Name.ToLower() == "consolehost") { if (MultiColor == false) { { if (MyInvocation.BoundParameters.ContainsKey("ConsoleLogLevel")) { switch (ConsoleLogLevel.ToLower()) { case "off": consoleAppender.Threshold = log4net.Core.Level.Off; break; case "info": consoleAppender.Threshold = log4net.Core.Level.Info; break; case "warn": consoleAppender.Threshold = log4net.Core.Level.Warn; break; case "error": consoleAppender.Threshold = log4net.Core.Level.Error; break; case "debug": consoleAppender.Threshold = log4net.Core.Level.Debug; break; default: consoleAppender.Threshold = log4net.Core.Level.Info; break; } } } } else { consoleAppender.Threshold = log4net.Core.Level.Off; } } else { if (this.Host.Name.ToLower() == "windows powershell ise host") { if (MyInvocation.BoundParameters.ContainsKey("ConsoleLogLevel")) { switch (ConsoleLogLevel.ToLower()) { case "off": consoleAppender.Threshold = log4net.Core.Level.Off; break; case "info": consoleAppender.Threshold = log4net.Core.Level.Info; break; case "warn": consoleAppender.Threshold = log4net.Core.Level.Warn; break; case "error": consoleAppender.Threshold = log4net.Core.Level.Error; break; case "debug": consoleAppender.Threshold = log4net.Core.Level.Debug; break; default: consoleAppender.Threshold = log4net.Core.Level.Info; break; } } if ((MyInvocation.BoundParameters.ContainsKey("MultiColor")) && (MultiColor == true)) { Console.WriteLine("Powershell ISe does not support multi colored displays."); } } } consoleAppender.ActivateOptions(); } #endregion #region coloredconsoleappender if (logAppender.GetType() == typeof(log4net.Appender.ColoredConsoleAppender)) { log4net.Appender.ColoredConsoleAppender coloredConsoleAppender = (log4net.Appender.ColoredConsoleAppender)logAppender; if (this.Host.Name.ToLower() == "consolehost") { if (MultiColor == true) { if (MyInvocation.BoundParameters.ContainsKey("ConsoleLogLevel")) { switch (ConsoleLogLevel.ToLower()) { case "off": coloredConsoleAppender.Threshold = log4net.Core.Level.Off; break; case "info": coloredConsoleAppender.Threshold = log4net.Core.Level.Info; break; case "warn": coloredConsoleAppender.Threshold = log4net.Core.Level.Warn; break; case "error": coloredConsoleAppender.Threshold = log4net.Core.Level.Error; break; case "debug": coloredConsoleAppender.Threshold = log4net.Core.Level.Debug; break; default: coloredConsoleAppender.Threshold = log4net.Core.Level.Info; break; } } } else { coloredConsoleAppender.Threshold = log4net.Core.Level.Off; } } if (this.Host.Name.ToLower() == "windows powershell ise host") { coloredConsoleAppender.Threshold = log4net.Core.Level.Off; } coloredConsoleAppender.ActivateOptions(); } #endregion } }