src/System.Management.Automation/utils/tracing/PSEtwLogProvider.cs
/// <summary>
/// Provider interface function for logging command lifecycle event
/// </summary>
/// <param name="getLogContext"></param>
/// <param name="newState"></param>
/// 
Provider interface function for logging command lifecycle event
Provider interface function for logging command lifecycle event
internal override void LogCommandLifecycleEvent(Func<LogContext> getLogContext, CommandState newState)
        {
            if (IsEnabled(PSLevel.Informational, PSKeyword.Cmdlets | PSKeyword.UseAlwaysAnalytic))
            {
                LogContext logContext = getLogContext();
                StringBuilder payload = new StringBuilder();
                if (logContext.CommandType != null)
                {
                    if (logContext.CommandType.Equals(StringLiterals.Script, StringComparison.OrdinalIgnoreCase))
                    {
                        payload.AppendLine(StringUtil.Format(EtwLoggingStrings.ScriptStateChange, newState.ToString()));
                    }
                    else
                    {
                        payload.AppendLine(StringUtil.Format(EtwLoggingStrings.CommandStateChange, logContext.CommandName, newState.ToString()));
                    }
                }
                PSTask task = PSTask.CommandStart;
                if (newState == CommandState.Stopped ||
                    newState == CommandState.Terminated)
                {
                    task = PSTask.CommandStop;
                }
                WriteEvent(PSEventId.Command_Lifecycle, PSChannel.Analytic, PSOpcode.Method, task, logContext, payload.ToString());
            }
        }
internal override void LogCommandLifecycleEvent ( Func < LogContext > getLogContext , CommandState newState ) { if ( IsEnabled ( PSLevel . Informational , PSKeyword . Cmdlets | PSKeyword . UseAlwaysAnalytic ) ) { LogContext logContext = getLogContext ( ) ; StringBuilder payload = new StringBuilder ( ) ; if ( logContext . CommandType != null ) { if ( logContext . CommandType . Equals ( StringLiterals . Script , StringComparison . OrdinalIgnoreCase ) ) { payload . AppendLine ( StringUtil . Format ( EtwLoggingStrings . ScriptStateChange , newState . ToString ( ) ) ) ; } else { payload . AppendLine ( StringUtil . Format ( EtwLoggingStrings . CommandStateChange , logContext . CommandName , newState . ToString ( ) ) ) ; } } PSTask task = PSTask . CommandStart ; if ( newState == CommandState . Stopped || newState == CommandState . Terminated ) { task = PSTask . CommandStop ; } WriteEvent ( PSEventId . Command_Lifecycle , PSChannel . Analytic , PSOpcode . Method , task , logContext , payload . ToString ( ) ) ; } }
Provider interface function for logging command lifecycle event
Provider interface function for logging command lifecycle event
getLogContext
Func<LogContext>
None
newState
CommandState
None