diff --git a/src/System.Management.Automation/CoreCLR/CorePsStub.cs b/src/System.Management.Automation/CoreCLR/CorePsStub.cs index f58d8d49eed..3170b545884 100644 --- a/src/System.Management.Automation/CoreCLR/CorePsStub.cs +++ b/src/System.Management.Automation/CoreCLR/CorePsStub.cs @@ -783,29 +783,6 @@ public static Guid GetActivityId() } } - internal static class PSEtwLog - { - static internal void LogAnalyticError(PSEventId id, PSOpcode opcode, PSTask task, PSKeyword keyword, params object[] args) { } - static internal void LogAnalyticWarning(PSEventId id, PSOpcode opcode, PSTask task, PSKeyword keyword, params object[] args) { } - static internal void LogAnalyticVerbose(PSEventId id, PSOpcode opcode, PSTask task, PSKeyword keyword, - Int64 objectId, - Int64 fragmentId, - int isStartFragment, - int isEndFragment, - UInt32 fragmentLength, - PSETWBinaryBlob fragmentData) - { } - static internal void LogAnalyticVerbose(PSEventId id, PSOpcode opcode, PSTask task, PSKeyword keyword, params object[] args) { } - static internal void SetActivityIdForCurrentThread(Guid newActivityId) { } - static internal void LogOperationalVerbose(PSEventId id, PSOpcode opcode, PSTask task, PSKeyword keyword, params object[] args) { } - static internal void LogOperationalWarning(PSEventId id, PSOpcode opcode, PSTask task, PSKeyword keyword, params object[] args) { } - static internal void ReplaceActivityIdForCurrentThread(Guid newActivityId, PSEventId eventForOperationalChannel, PSEventId eventForAnalyticChannel, PSKeyword keyword, PSTask task) { } - static internal void LogOperationalError(PSEventId id, PSOpcode opcode, PSTask task, PSKeyword keyword, params object[] args) { } - static internal void LogOperationalError(PSEventId id, PSOpcode opcode, PSTask task, LogContext logContext, string payLoad) { } - static internal void LogAnalyticInformational(PSEventId id, PSOpcode opcode, PSTask task, PSKeyword keyword, params object[] args) { } - static internal void LogOperationalInformation(PSEventId id, PSOpcode opcode, PSTask task, PSKeyword keyword, params object[] args) { } - } - public enum PowerShellTraceTask { /// diff --git a/src/System.Management.Automation/CoreCLR/EventResource.cs b/src/System.Management.Automation/CoreCLR/EventResource.cs new file mode 100755 index 00000000000..9ff6f38d402 --- /dev/null +++ b/src/System.Management.Automation/CoreCLR/EventResource.cs @@ -0,0 +1,616 @@ +#if UNIX +/* + This code was generated by the tools\ResxGen\ResxGen.ps1 run against PowerShell-Core-Instrumentation.man. + To add or change logged events and the associated resources, edit PowerShell-Core-Instrumentation.man + then rerun ResxGen.ps1 to produce an updated CS and Resx file. +*/ +using System.Collections.Generic; +using System.Management.Automation.Internal; +using System.Runtime.InteropServices; + +namespace System.Management.Automation.Tracing +{ + /// + /// Provides a class for describing a message resource for an ETW event. + /// + internal static class EventResource + { + // Defines the resource id of the message to use when an event id is not valid. + private const string MissingEventIdResourceName = "MissingEventIdMessage"; + + /// + /// Gets the name of the message resource to use for event ids that are not found. + /// is not found. + /// + /// + /// This method is called when GetMessage returns a null value indicating the passed + /// in event id was not found. The message should be used as the format string + /// with the event id as the single variable argument. + /// + public static string GetMissingEventMessage(out int parameterCount) + { + parameterCount = 1; + return MissingEventIdResourceName; + } + + /// + /// Gets the message resource id for the specified event id + /// + /// The event id for the message resource to retrieve. + /// The number of parameters required by the message resource + /// The string resource id of the associated event message; otherwise, a null reference if the event id is not valid. + public static string GetMessage(int eventId, out int parameterCount) + { + switch (eventId) + { + case 4097: + parameterCount = 0; + return "PS_PROVIDEReventE_O_CMDLETS_HOSTNAMERESOLVE"; + case 4098: + parameterCount = 0; + return "PS_PROVIDEReventE_O_CMDLETS_SCHEMERESOLVE"; + case 4099: + parameterCount = 0; + return "PS_PROVIDEReventE_O_CMDLETS_SHELLRESOLVE"; + case 4100: + parameterCount = 3; + return "PS_PROVIDEReventE_O_COMMAND_HEALTH"; + case 4101: + parameterCount = 3; + return "PS_PROVIDEReventE_O_ENGINE_HEALTH"; + case 4102: + parameterCount = 3; + return "PS_PROVIDEReventE_O_PROVIDER_HEALTH"; + case 4103: + parameterCount = 3; + return "PS_PROVIDEReventE_O_PIPELINE_DETAIL"; + case 4104: + parameterCount = 5; + return "PS_PROVIDEReventE_O_SCRIPTBLOCK_CREATE_DETAIL"; + case 4105: + parameterCount = 2; + return "PS_PROVIDEReventE_O_SCRIPTBLOCK_INVOKE_START_DETAIL"; + case 4106: + parameterCount = 2; + return "PS_PROVIDEReventE_O_SCRIPTBLOCK_INVOKE_COMPLETE_DETAIL"; + case 7937: + parameterCount = 3; + return "PS_PROVIDEReventE_A_COMMAND_LIFECYCLE"; + case 7938: + parameterCount = 3; + return "PS_PROVIDEReventE_A_ENGINE_LIFECYCLE"; + case 7939: + parameterCount = 3; + return "PS_PROVIDEReventE_A_PROVIDER_LIFECYCLE"; + case 7940: + parameterCount = 3; + return "PS_PROVIDEReventE_A_SETTINGS"; + case 7941: + parameterCount = 2; + return "PS_PROVIDEReventE_A_WriteTransferEvent"; + case 7942: + parameterCount = 8; + return "PS_PROVIDEReventE_A_ENGINE_TRACE"; + case 8193: + parameterCount = 1; + return "PS_PROVIDEReventE_O_RUNSPACE_CONSTRUCTOR"; + case 8194: + parameterCount = 3; + return "PS_PROVIDEReventE_O_RUNSPACEPOOL_CONSTRUCTOR"; + case 8195: + parameterCount = 0; + return "PS_PROVIDEReventE_O_RUNSPACEPOOL_OPEN"; + case 8196: + parameterCount = 0; + return "PS_PROVIDEReventE_O_RUNSPACEPOOL_TRANSFER"; + case 8197: + parameterCount = 1; + return "PS_PROVIDEReventE_O_RUNSPACE_STATE_CHANGE"; + case 8198: + parameterCount = 3; + return "PS_PROVIDEReventE_O_REMOTE_RUNSPACE_CREATE_RETRY"; + case 12033: + parameterCount = 1; + return "PS_PROVIDEReventE_A_RUNSPACE_PORT"; + case 12034: + parameterCount = 1; + return "PS_PROVIDEReventE_A_RUNSPACE_APPNAME"; + case 12035: + parameterCount = 1; + return "PS_PROVIDEReventE_A_RUNSPACE_COMPUTERNAME"; + case 12036: + parameterCount = 1; + return "PS_PROVIDEReventE_A_RUNSPACE_SCHEME"; + case 12037: + parameterCount = 0; + return "PS_PROVIDEReventE_A_RUNSPACE_TEST"; + case 12038: + parameterCount = 9; + return "PS_PROVIDEReventE_A_RUNSPACE_WSMANCONNECTIONINFO"; + case 12039: + parameterCount = 0; + return "PS_PROVIDEReventE_A_RUNSPACEPOOL_TRANSFER"; + case 24577: + parameterCount = 1; + return "PS_PROVIDEReventE_O_ISEExecuteScript"; + case 24578: + parameterCount = 1; + return "PS_PROVIDEReventE_O_ISEExecuteSelection"; + case 24579: + parameterCount = 0; + return "PS_PROVIDEReventE_O_ISEStopCommand"; + case 24580: + parameterCount = 0; + return "PS_PROVIDEReventE_O_ISEResumeDebugger"; + case 24581: + parameterCount = 0; + return "PS_PROVIDEReventE_O_ISEStopDebugger"; + case 24582: + parameterCount = 0; + return "PS_PROVIDEReventE_O_ISEDebuggerStepInto"; + case 24583: + parameterCount = 0; + return "PS_PROVIDEReventE_O_ISEDebuggerStepOver"; + case 24584: + parameterCount = 0; + return "PS_PROVIDEReventE_O_ISEDebuggerStepOut"; + case 24592: + parameterCount = 0; + return "PS_PROVIDEReventE_O_ISEEnableAllBreakpoints"; + case 24593: + parameterCount = 0; + return "PS_PROVIDEReventE_O_ISEDisableAllBreakpoints"; + case 24594: + parameterCount = 0; + return "PS_PROVIDEReventE_O_ISERemoveAllBreakpoints"; + case 24595: + parameterCount = 2; + return "PS_PROVIDEReventE_O_ISESetBreakpoint"; + case 24596: + parameterCount = 2; + return "PS_PROVIDEReventE_O_ISERemoveBreakpoint"; + case 24597: + parameterCount = 2; + return "PS_PROVIDEReventE_O_ISEEnableBreakpoint"; + case 24598: + parameterCount = 2; + return "PS_PROVIDEReventE_O_ISEDisableBreakpoint"; + case 24599: + parameterCount = 2; + return "PS_PROVIDEReventE_O_ISEHitBreakpoint"; + case 28673: + parameterCount = 3; + return "PS_PROVIDEReventE_A_SERIALIZER_REHYDRATION_SUCCESS"; + case 28674: + parameterCount = 4; + return "PS_PROVIDEReventE_A_SERIALIZER_REHYDRATION_FAILURE"; + case 28675: + parameterCount = 4; + return "PS_PROVIDEReventE_A_SERIALIZER_DEPTH_OVERRIDE"; + case 28676: + parameterCount = 2; + return "PS_PROVIDEReventE_A_SERIALIZER_MODE_OVERRIDE"; + case 28677: + parameterCount = 3; + return "PS_PROVIDEReventE_A_SERIALIZER_SCRIPT_PROPERTY_WITHOUT_RUNSPACE"; + case 28678: + parameterCount = 4; + return "PS_PROVIDEReventE_A_SERIALIZER_PROPERTY_GETTER_FAILED"; + case 28679: + parameterCount = 2; + return "PS_PROVIDEReventE_A_SERIALIZER_ENUMERATION_FAILED"; + case 28680: + parameterCount = 2; + return "PS_PROVIDEReventE_A_SERIALIZER_TOSTRING_FAILED"; + case 28682: + parameterCount = 3; + return "PS_PROVIDEReventE_A_SERIALIZER_MAX_DEPTH_WHEN_SERIALIZING"; + case 28683: + parameterCount = 3; + return "PS_PROVIDEReventE_A_SERIALIZER_XMLEXCEPTION_WHEN_DESERIALIZING"; + case 28684: + parameterCount = 2; + return "PS_PROVIDEReventE_A_SERIALIZER_SPECIFIC_PROPERTY_MISSING"; + case 32769: + parameterCount = 5; + return "PS_PROVIDEReventE_A_TRANSPORT_RCVDOBJ"; + case 32775: + parameterCount = 3; + return "PS_PROVIDEReventE_A_APPDOMAIN_UNHANDLED_EXCEPTION"; + case 32776: + parameterCount = 5; + return "PS_PROVIDEReventE_A_TRANSPORT_ERROR"; + case 32777: + parameterCount = 3; + return "PS_PROVIDEReventE_O_APPDOMAIN_UNHANDLED_EXCEPTION"; + case 32784: + parameterCount = 5; + return "PS_PROVIDEReventE_O_TRANSPORT_ERROR"; + case 32785: + parameterCount = 1; + return "PS_PROVIDEReventE_A_TRANSPORT_CONNECT"; + case 32786: + parameterCount = 1; + return "PS_PROVIDEReventE_A_TRANSPORT_SHELL_CONNECT_CALLBACK"; + case 32787: + parameterCount = 1; + return "PS_PROVIDEReventE_A_TRANSPORT_SHELL_CLOSE"; + case 32788: + parameterCount = 1; + return "PS_PROVIDEReventE_A_TRANSPORT_SHELL_CLOSE_CALLBACK"; + case 32789: + parameterCount = 3; + return "PS_PROVIDEReventE_A_TRANSPORT_SEND_DATA"; + case 32790: + parameterCount = 2; + return "PS_PROVIDEReventE_A_TRANSPORT_SEND_DATA_CALLBACK"; + case 32791: + parameterCount = 2; + return "PS_PROVIDEReventE_A_TRANSPORT_RECEIVE_DATA"; + case 32792: + parameterCount = 3; + return "PS_PROVIDEReventE_A_TRANSPORT_RECEIVE_DATA_CALLBACK"; + case 32793: + parameterCount = 2; + return "PS_PROVIDEReventE_A_TRANSPORT_CMD_CONNECT"; + case 32800: + parameterCount = 2; + return "PS_PROVIDEReventE_A_TRANSPORT_CMD_CONNECT_CALLBACK"; + case 32801: + parameterCount = 2; + return "PS_PROVIDEReventE_A_TRANSPORT_CMD_CLOSE"; + case 32802: + parameterCount = 2; + return "PS_PROVIDEReventE_A_TRANSPORT_CMD_CLOSE_CALLBACK"; + case 32803: + parameterCount = 3; + return "PS_PROVIDEReventE_A_TRANSPORT_SIGNAL"; + case 32804: + parameterCount = 2; + return "PS_PROVIDEReventE_A_TRANSPORT_SIGNAL_CALLBACK"; + case 32805: + parameterCount = 2; + return "PS_PROVIDEReventE_A_TRANSPORT_URI_REDIRECTION"; + case 32849: + parameterCount = 5; + return "PS_PROVIDEReventE_A_TRANSPORT_SERVER_SEND_DATA"; + case 32850: + parameterCount = 3; + return "PS_PROVIDEReventE_A_CREATE_SERVER_REMOTESESSION"; + case 32851: + parameterCount = 1; + return "PS_PROVIDEReventE_A_REPORT_CONTEXT"; + case 32852: + parameterCount = 4; + return "PS_PROVIDEReventE_A_REPORT_OPERATION_COMPLETE"; + case 32853: + parameterCount = 2; + return "PS_PROVIDEReventE_A_CREATE_COMMAND_REMOTESESSION"; + case 32854: + parameterCount = 3; + return "PS_PROVIDEReventE_A_STOP_COMMAND"; + case 32855: + parameterCount = 3; + return "PS_PROVIDEReventE_A_SERVER_RECEIVED_DATA"; + case 32856: + parameterCount = 3; + return "PS_PROVIDEReventE_A_SERVER_RECEIVE_REQUEST"; + case 32857: + parameterCount = 3; + return "PS_PROVIDEReventE_A_SERVER_CLOSE_OPERATION"; + case 32865: + parameterCount = 2; + return "PS_PROVIDEReventE_A_LOAD_PSCUSTOMSHELL_ASSEMBLY"; + case 32866: + parameterCount = 2; + return "PS_PROVIDEReventE_A_LOAD_PSCUSTOMSHELL_TYPE"; + case 32867: + parameterCount = 6; + return "PS_PROVIDEReventE_A_RECEIVED_FRAGMENT"; + case 32868: + parameterCount = 6; + return "PS_PROVIDEReventE_A_SENT_FRAGMENT"; + case 32869: + parameterCount = 0; + return "PS_PROVIDEReventE_A_SHUTTING_DOWN"; + case 40961: + parameterCount = 0; + return "PS_PROVIDEReventE_O_PowershellConsoleStartupStart"; + case 40962: + parameterCount = 0; + return "PS_PROVIDEReventE_O_PowershellConsoleStartupStop"; + case 45057: + parameterCount = 8; + return "PS_PROVIDEReventE_D_Powershell_ErrorRecord"; + case 45058: + parameterCount = 3; + return "PS_PROVIDEReventE_D_Powershell_Exception"; + case 45059: + parameterCount = 0; + return "PS_PROVIDEReventE_O_Powershell_PSObject"; + case 45060: + parameterCount = 6; + return "PS_PROVIDEReventE_D_Powershell_Job"; + case 45061: + parameterCount = 1; + return "PS_PROVIDEReventE_D_MESSAGE"; + case 45062: + parameterCount = 9; + return "PS_PROVIDEReventE_A_RUNSPACE_WSMANCONNECTIONINFO"; + case 45063: + parameterCount = 5; + return "PS_PROVIDEReventE_O_M3PWorkflowPluginStarted"; + case 45064: + parameterCount = 2; + return "PS_PROVIDEReventE_O_M3PWorkflowExecutionStarted"; + case 45065: + parameterCount = 3; + return "PS_PROVIDEReventE_O_M3PWorkflowStateChanged"; + case 45072: + parameterCount = 1; + return "PS_PROVIDEReventE_O_M3PWorkflowPluginRequestedToShutdown"; + case 45073: + parameterCount = 1; + return "PS_PROVIDEReventE_O_M3PWorkflowPluginRestarted"; + case 45074: + parameterCount = 1; + return "PS_PROVIDEReventE_O_M3PWorkflowWorkflowsResuming"; + case 45075: + parameterCount = 4; + return "PS_PROVIDEReventE_O_M3PWorkflowQuotaViolationDetected"; + case 45076: + parameterCount = 1; + return "PS_PROVIDEReventE_O_M3PWorkflowWorkflowsResumed"; + case 45078: + parameterCount = 2; + return "PS_PROVIDEReventE_O_M3PWorkflowRunspacePoolCreated"; + case 45079: + parameterCount = 2; + return "PS_PROVIDEReventE_O_M3PWorkflowActivityExecutionQueued"; + case 45080: + parameterCount = 2; + return "PS_PROVIDEReventE_O_M3PWorkflowActivityExecutionStarted"; + case 45081: + parameterCount = 2; + return "PS_PROVIDEReventE_O_M3PWorkflowImportingFromXaml"; + case 45082: + parameterCount = 2; + return "PS_PROVIDEReventE_O_M3PWorkflowImportedFromXaml"; + case 45083: + parameterCount = 2; + return "PS_PROVIDEReventE_O_M3PWorkflowImportFromXamlError"; + case 45084: + parameterCount = 1; + return "PS_PROVIDEReventE_O_M3PWorkflowImportFromXamlValidationStarted"; + case 45085: + parameterCount = 1; + return "PS_PROVIDEReventE_O_M3PWorkflowImportFromXamlValidationFinishedSuccessfully"; + case 45086: + parameterCount = 1; + return "PS_PROVIDEReventE_O_M3PWorkflowImportFromXamlValidationFinishedWithError"; + case 45087: + parameterCount = 3; + return "PS_PROVIDEReventE_O_M3PWorkflowImportFromXamlActivityValidated"; + case 45088: + parameterCount = 3; + return "PS_PROVIDEReventE_O_M3PWorkflowImportFromXamlActivityValidationFailed"; + case 45089: + parameterCount = 3; + return "PS_PROVIDEReventE_O_M3PWorkflowActivityExecutionFailed"; + case 45090: + parameterCount = 2; + return "PS_PROVIDEReventE_O_M3PWorkflowRunspaceAvailabilityChanged"; + case 45091: + parameterCount = 3; + return "PS_PROVIDEReventE_O_M3PWorkflowRunspaceStateChanged"; + case 45092: + parameterCount = 1; + return "PS_PROVIDEReventE_O_M3PWorkflowLoadedForExecution"; + case 45093: + parameterCount = 1; + return "PS_PROVIDEReventE_O_M3PWorkflowUnloaded"; + case 45094: + parameterCount = 1; + return "PS_PROVIDEReventE_O_M3PWorkflowCancelled"; + case 45095: + parameterCount = 1; + return "PS_PROVIDEReventE_O_M3PWorkflowAborted"; + case 45096: + parameterCount = 1; + return "PS_PROVIDEReventE_O_M3PWorkflowCleanup"; + case 45097: + parameterCount = 2; + return "PS_PROVIDEReventE_O_M3PWorkflowLoadedFromDisk"; + case 45098: + parameterCount = 2; + return "PS_PROVIDEReventE_O_M3PWorkflowDeletedFromDisk"; + case 45100: + parameterCount = 1; + return "PS_PROVIDEReventE_O_M3PRemoveJobStarted"; + case 45101: + parameterCount = 4; + return "PS_PROVIDEReventE_O_M3PJobStateChanged"; + case 45102: + parameterCount = 3; + return "PS_PROVIDEReventE_O_M3PJobError"; + case 45104: + parameterCount = 3; + return "PS_PROVIDEReventE_O_M3PWorkflowJobCreated"; + case 45105: + parameterCount = 1; + return "PS_PROVIDEReventE_O_M3PParentJobCreated"; + case 45106: + parameterCount = 2; + return "PS_PROVIDEReventE_O_M3PJobCreationCompleted"; + case 45107: + parameterCount = 3; + return "PS_PROVIDEReventE_O_M3PJobRemoved"; + case 45108: + parameterCount = 4; + return "PS_PROVIDEReventE_O_M3PJobRemoveError"; + case 45109: + parameterCount = 1; + return "PS_PROVIDEReventE_O_M3PLoadingWorkflowForExecution"; + case 45110: + parameterCount = 1; + return "PS_PROVIDEReventE_O_M3PWorkflowExecutionFinished"; + case 45111: + parameterCount = 1; + return "PS_PROVIDEReventE_O_M3PCancellingWorkflowExecution"; + case 45112: + parameterCount = 2; + return "PS_PROVIDEReventE_O_M3PAbortingWorkflowExecution"; + case 45113: + parameterCount = 1; + return "PS_PROVIDEReventE_O_M3PUnloadingWorkflow"; + case 45114: + parameterCount = 1; + return "PS_PROVIDEReventE_O_M3PForcedWorkflowShutdownStarted"; + case 45115: + parameterCount = 1; + return "PS_PROVIDEReventE_O_M3PForcedWorkflowShutdownFinished"; + case 45116: + parameterCount = 2; + return "PS_PROVIDEReventE_O_M3PForcedWorkflowShutdownError"; + case 45117: + parameterCount = 2; + return "PS_PROVIDEReventE_O_M3PPersistingWorkflow"; + case 45118: + parameterCount = 1; + return "PS_PROVIDEReventE_O_M3PWorkflowPersisted"; + case 45119: + parameterCount = 1; + return "PS_PROVIDEReventE_O_M3PWorkflowActivityExecutionFinished"; + case 45120: + parameterCount = 2; + return "PS_PROVIDEReventE_O_M3PWorkflowExecutionError"; + case 45121: + parameterCount = 3; + return "PS_PROVIDEReventE_O_M3PEndpointRegistered"; + case 45122: + parameterCount = 2; + return "PS_PROVIDEReventE_O_M3PEndpointModified"; + case 45123: + parameterCount = 2; + return "PS_PROVIDEReventE_O_M3PEndpointUnregistered"; + case 45124: + parameterCount = 2; + return "PS_PROVIDEReventE_O_M3PEndpointDisabled"; + case 45125: + parameterCount = 2; + return "PS_PROVIDEReventE_O_M3PEndpointEnabled"; + case 45126: + parameterCount = 1; + return "PS_PROVIDEReventE_O_M3POutOfProcessRunspaceStarted"; + case 45127: + parameterCount = 2; + return "PS_PROVIDEReventE_O_M3PParameterSplattingWasPerformed"; + case 45128: + parameterCount = 1; + return "PS_PROVIDEReventE_O_M3PWorkflowEngineStarted"; + case 45129: + parameterCount = 4; + return "PS_PROVIDEReventE_D_M3PWORKFLOW_MANAGER_CHECKPOINTPATH"; + case 46337: + parameterCount = 1; + return "PS_PROVIDEReventE_D_M3PBeginStartWorkflowApplication"; + case 46338: + parameterCount = 1; + return "PS_PROVIDEReventE_D_M3PEndStartWorkflowApplication"; + case 46339: + parameterCount = 1; + return "PS_PROVIDEReventE_D_M3PBeginCreateNewJob"; + case 46340: + parameterCount = 1; + return "PS_PROVIDEReventE_D_M3PEndCreateNewJob"; + case 46341: + parameterCount = 2; + return "PS_PROVIDEReventE_D_M3PTrackingGuidContainerParentJobCorrelation"; + case 46342: + parameterCount = 1; + return "PS_PROVIDEReventE_D_M3PBeginJobLogic"; + case 46343: + parameterCount = 1; + return "PS_PROVIDEReventE_D_M3PEndJobLogic"; + case 46344: + parameterCount = 1; + return "PS_PROVIDEReventE_D_M3PBeginWorkflowExecution"; + case 46345: + parameterCount = 1; + return "PS_PROVIDEReventE_D_M3PEndWorkflowExecution"; + case 46346: + parameterCount = 2; + return "PS_PROVIDEReventE_D_M3PChildWorkflowJobAddition"; + case 46347: + parameterCount = 2; + return "PS_PROVIDEReventE_D_M3PProxyJobRemoteJobAssociation"; + case 46348: + parameterCount = 1; + return "PS_PROVIDEReventE_D_M3PBeginContainerParentJobExecution"; + case 46349: + parameterCount = 1; + return "PS_PROVIDEReventE_D_M3PEndContainerParentJobExecution"; + case 46350: + parameterCount = 1; + return "PS_PROVIDEReventE_D_M3PBeginProxyJobExecution"; + case 46351: + parameterCount = 1; + return "PS_PROVIDEReventE_D_M3PEndProxyJobExecution"; + case 46352: + parameterCount = 1; + return "PS_PROVIDEReventE_D_M3PBeginProxyJobEventHandler"; + case 46353: + parameterCount = 1; + return "PS_PROVIDEReventE_D_M3PEndProxyJobEventHandler"; + case 46354: + parameterCount = 1; + return "PS_PROVIDEReventE_D_M3PBeginProxyChildJobEventHandler"; + case 46355: + parameterCount = 1; + return "PS_PROVIDEReventE_D_M3PEndProxyChildJobEventHandler"; + case 46356: + parameterCount = 0; + return "PS_PROVIDEReventE_D_M3PBeginRunGarbageCollection"; + case 46357: + parameterCount = 0; + return "PS_PROVIDEReventE_D_M3PEndRunGarbageCollection"; + case 46358: + parameterCount = 0; + return "PS_PROVIDEReventE_O_M3PPERSISTENCE_STORE_MAXSIZE_REACHED"; + case 49152: + parameterCount = 1; + return "PS_PROVIDEReventE_D_DebugMessage"; + case 49153: + parameterCount = 2; + return "PS_PROVIDEReventE_D_MESSAGE2"; + case 53249: + parameterCount = 2; + return "PS_PROVIDEReventE_O_ScheduledJobStarted"; + case 53250: + parameterCount = 3; + return "PS_PROVIDEReventE_O_ScheduledJobCompleted"; + case 53251: + parameterCount = 4; + return "PS_PROVIDEReventE_O_ScheduledJobException"; + case 53504: + parameterCount = 2; + return "PS_PROVIDEReventE_O_REMOTE_NAMEDPIPE_LISTENER_START"; + case 53505: + parameterCount = 2; + return "PS_PROVIDEReventE_O_REMOTE_NAMEDPIPE_LISTENER_END"; + case 53506: + parameterCount = 3; + return "PS_PROVIDEReventE_O_REMOTE_NAMEDPIPE_LISTENER_ERROR"; + case 53507: + parameterCount = 3; + return "PS_PROVIDEReventE_O_REMOTE_NAMEDPIPE_CONNECT"; + case 53508: + parameterCount = 3; + return "PS_PROVIDEReventE_O_REMOTE_NAMEDPIPE_DISCONNECT"; + } + parameterCount = 0; + return null; + } + } +} +#endif diff --git a/src/System.Management.Automation/System.Management.Automation.csproj b/src/System.Management.Automation/System.Management.Automation.csproj index a9c43f67117..98cc8af08fd 100644 --- a/src/System.Management.Automation/System.Management.Automation.csproj +++ b/src/System.Management.Automation/System.Management.Automation.csproj @@ -119,6 +119,7 @@ + diff --git a/src/System.Management.Automation/engine/PropertyAccessor.cs b/src/System.Management.Automation/engine/PropertyAccessor.cs index eade35a7f66..d44e34461fa 100644 --- a/src/System.Management.Automation/engine/PropertyAccessor.cs +++ b/src/System.Management.Automation/engine/PropertyAccessor.cs @@ -9,6 +9,7 @@ using System.Threading; using System.Management.Automation; +using System.Management.Automation.Internal; using Microsoft.Win32; using Newtonsoft.Json; @@ -101,6 +102,51 @@ internal enum PropertyScope internal abstract string GetDefaultSourcePath(); internal abstract void SetDefaultSourcePath(string defaultPath); +#if UNIX + /// + /// Gets the application identity (name) to use for writing to syslog. + /// + /// + /// The string identity to use for writing to syslog. + /// + /// The default value is 'powershell' + /// + /// + internal abstract string GetSysLogIdentity(); + + /// + /// Gets the log level filter. + /// + /// One of the PSLevel values indicating the level to log. + /// + /// The default value is PSLevel.Informational + /// + /// + internal abstract PSLevel GetLogLevel(); + + /// + /// Gets the bitmask of the PSChannel values to log. + /// + /// + /// A bitmask of PSChannel.Operational and/or PSChannel.Analytic + /// + /// The default value is PSChannel.Operational + /// + /// + internal abstract PSChannel GetLogChannels(); + + /// + /// Gets the bitmask of keywords to log. + /// + /// + /// A bitmask of PSKeyword values. + /// + /// The default value is all keywords other than UseAlwaysAnalytic + /// + /// + internal abstract PSKeyword GetLogKeywords(); + +#endif // UNIX #endregion // Interface Methods } @@ -310,6 +356,155 @@ internal override void SetDefaultSourcePath(string defaultPath) WriteValueToFile(fileName, "DefaultSourcePath", defaultPath); } +#if UNIX + /// + /// Gets the identity name to use for writing to syslog. + /// + /// + /// The string identity to use for writing to syslog. + /// + /// The default value is 'powershell'. + /// + /// + internal override string GetSysLogIdentity() + { + string fileName = Path.Combine(psHomeConfigDirectory, configFileName); + string identity = ReadValueFromFile(fileName, "LogIdentity"); + + if (string.IsNullOrEmpty(identity) || + identity.Equals(LogDefaultValue, StringComparison.OrdinalIgnoreCase)) + { + identity = "powershell"; + } + return identity; + } + + /// + /// Gets the log level filter. + /// + /// One of the PSLevel values indicating the level to log. + /// + /// The default value is PSLevel.Informational. + /// + /// + internal override PSLevel GetLogLevel() + { + string fileName = Path.Combine(psHomeConfigDirectory, configFileName); + string levelName = ReadValueFromFile(fileName, "LogLevel"); + PSLevel level; + + if (string.IsNullOrEmpty(levelName) || + levelName.Equals(LogDefaultValue, StringComparison.OrdinalIgnoreCase) || + !Enum.TryParse(levelName, true, out level)) + { + level = PSLevel.Informational; + } + return level; + } + + /// + /// The supported separator characters for listing channels and keywords in configuration. + /// + static readonly char[] s_valueSeparators = new char[] {' ', ',', '|'}; + + /// + /// Provides a string name to indicate the default for a configuration setting. + /// + const string LogDefaultValue = "default"; + + const PSChannel DefaultChannels = PSChannel.Operational; + + /// + /// Gets the bitmask of the PSChannel values to log. + /// + /// + /// A bitmask of PSChannel.Operational and/or PSChannel.Analytic. + /// + /// The default value is PSChannel.Operational. + /// + /// + internal override PSChannel GetLogChannels() + { + string fileName = Path.Combine(psHomeConfigDirectory, configFileName); + string values = ReadValueFromFile(fileName, "LogChannels"); + + PSChannel result = 0; + if (!string.IsNullOrEmpty(values)) + { + string[] names = values.Split(s_valueSeparators, StringSplitOptions.RemoveEmptyEntries); + + foreach (string name in names) + { + if (name.Equals(LogDefaultValue, StringComparison.OrdinalIgnoreCase)) + { + result = 0; + break; + } + + PSChannel value; + if (Enum.TryParse(name, true, out value)) + { + result |= value; + } + } + } + + if (result == 0) + { + result = DefaultChannels; + } + + return result; + } + + // by default, do not include analytic events. + const PSKeyword DefaultKeywords = (PSKeyword) (0xFFFFFFFFFFFFFFFF & ~(ulong)PSKeyword.UseAlwaysAnalytic); + + /// + /// Gets the bitmask of keywords to log. + /// + /// + /// A bitmask of PSKeyword values. + /// + /// The default value is all keywords other than UseAlwaysAnalytic. + /// + /// + internal override PSKeyword GetLogKeywords() + { + string fileName = Path.Combine(psHomeConfigDirectory, configFileName); + string values = ReadValueFromFile(fileName, "LogKeywords"); + + PSKeyword result = 0; + if (!string.IsNullOrEmpty(values)) + { + string[] names = values.Split(s_valueSeparators, StringSplitOptions.RemoveEmptyEntries); + + foreach (string name in names) + { + if (name.Equals(LogDefaultValue, StringComparison.OrdinalIgnoreCase)) + { + result = 0; + break; + } + + PSKeyword value; + if (Enum.TryParse(name, true, out value)) + { + result |= value; + } + } + } + + if (result == 0) + { + result = DefaultKeywords; + } + + return result; + } + +#endif // UNIX + private T ReadValueFromFile(string fileName, string key) { fileLock.EnterReadLock(); diff --git a/src/System.Management.Automation/engine/remoting/common/PSETWTracer.cs b/src/System.Management.Automation/engine/remoting/common/PSETWTracer.cs index 54ae63b4fbf..5008ab57dde 100644 --- a/src/System.Management.Automation/engine/remoting/common/PSETWTracer.cs +++ b/src/System.Management.Automation/engine/remoting/common/PSETWTracer.cs @@ -9,6 +9,7 @@ namespace System.Management.Automation.Internal /// /// Defines enumerations for the keywords /// + [Flags] internal enum PSKeyword : ulong { Runspace = 0x1, @@ -194,6 +195,7 @@ internal enum PSEventId : int /// /// Defines enumerations for channels /// + [Flags] internal enum PSChannel : byte { Operational = 0x10, diff --git a/src/System.Management.Automation/logging/LogProvider.cs b/src/System.Management.Automation/logging/LogProvider.cs index 362a417c67c..c5445c010e9 100644 --- a/src/System.Management.Automation/logging/LogProvider.cs +++ b/src/System.Management.Automation/logging/LogProvider.cs @@ -3,6 +3,8 @@ --********************************************************************/ using System.Collections.Generic; +using System.Text; +using System.Management.Automation.Internal; namespace System.Management.Automation { @@ -119,6 +121,170 @@ internal virtual bool UseLoggingVariables() } #endregion + + #region Shared utilities + + private static class Strings + { + // The strings are stored in a different class to defer loading the resources until as late + // as possible, e.g. if logging is never on, these strings won't be loaded. + internal static readonly string LogContextSeverity = EtwLoggingStrings.LogContextSeverity; + internal static readonly string LogContextHostName = EtwLoggingStrings.LogContextHostName; + internal static readonly string LogContextHostVersion = EtwLoggingStrings.LogContextHostVersion; + internal static readonly string LogContextHostId = EtwLoggingStrings.LogContextHostId; + internal static readonly string LogContextHostApplication = EtwLoggingStrings.LogContextHostApplication; + internal static readonly string LogContextEngineVersion = EtwLoggingStrings.LogContextEngineVersion; + internal static readonly string LogContextRunspaceId = EtwLoggingStrings.LogContextRunspaceId; + internal static readonly string LogContextPipelineId = EtwLoggingStrings.LogContextPipelineId; + internal static readonly string LogContextCommandName = EtwLoggingStrings.LogContextCommandName; + internal static readonly string LogContextCommandType = EtwLoggingStrings.LogContextCommandType; + internal static readonly string LogContextScriptName = EtwLoggingStrings.LogContextScriptName; + internal static readonly string LogContextCommandPath = EtwLoggingStrings.LogContextCommandPath; + internal static readonly string LogContextSequenceNumber = EtwLoggingStrings.LogContextSequenceNumber; + internal static readonly string LogContextUser = EtwLoggingStrings.LogContextUser; + internal static readonly string LogContextConnectedUser = EtwLoggingStrings.LogContextConnectedUser; + internal static readonly string LogContextTime = EtwLoggingStrings.LogContextTime; + internal static readonly string LogContextShellId = EtwLoggingStrings.LogContextShellId; + } + + /// + /// Gets PSLogUserData from execution context. + /// + /// + /// + protected static string GetPSLogUserData(ExecutionContext context) + { + if (context == null) + { + return String.Empty; + } + + object logData = context.GetVariableValue(SpecialVariables.PSLogUserDataPath); + + if (logData == null) + { + return String.Empty; + } + + return logData.ToString(); + } + + /// + /// Appends exception information. + /// + /// string builder. + /// exception. + protected static void AppendException(StringBuilder sb, Exception except) + { + sb.AppendLine(StringUtil.Format(EtwLoggingStrings.ErrorRecordMessage, except.Message)); + + IContainsErrorRecord ier = except as IContainsErrorRecord; + + if (ier != null) + { + ErrorRecord er = ier.ErrorRecord; + + if (er != null) + { + sb.AppendLine(StringUtil.Format(EtwLoggingStrings.ErrorRecordId, er.FullyQualifiedErrorId)); + + ErrorDetails details = er.ErrorDetails; + + if (details != null) + { + sb.AppendLine(StringUtil.Format(EtwLoggingStrings.ErrorRecordRecommendedAction, details.RecommendedAction)); + } + } + } + } + + /// + /// Appends additional information. + /// + /// string builder. + /// additional information. + protected static void AppendAdditionalInfo(StringBuilder sb, Dictionary additionalInfo) + { + if (additionalInfo != null) + { + foreach (KeyValuePair value in additionalInfo) + { + sb.AppendLine(StringUtil.Format("{0} = {1}", value.Key, value.Value)); + } + } + } + + /// + /// Gets PSLevel from severity. + /// + /// error severity. + /// PS log level. + protected static PSLevel GetPSLevelFromSeverity(string severity) + { + switch (severity) + { + case "Critical": + case "Error": + return PSLevel.Error; + case "Warning": + return PSLevel.Warning; + default: + return PSLevel.Informational; + } + } + + // Estimate an approximate size to use for the StringBuilder in LogContextToString + // Estimated length of all Strings.* values + // Rough estimate of values + // max path for Command path + const int LogContextInitialSize = 30 * 16 + 13 * 20 + 255; + + /// + /// Converts log context to string + /// + /// log context + /// string representation + protected static string LogContextToString(LogContext context) + { + StringBuilder sb = new StringBuilder(LogContextInitialSize); + + sb.Append(Strings.LogContextSeverity); + sb.AppendLine(context.Severity); + sb.Append(Strings.LogContextHostName); + sb.AppendLine(context.HostName); + sb.Append(Strings.LogContextHostVersion); + sb.AppendLine(context.HostVersion); + sb.Append(Strings.LogContextHostId); + sb.AppendLine(context.HostId); + sb.Append(Strings.LogContextHostApplication); + sb.AppendLine(context.HostApplication); + sb.Append(Strings.LogContextEngineVersion); + sb.AppendLine(context.EngineVersion); + sb.Append(Strings.LogContextRunspaceId); + sb.AppendLine(context.RunspaceId); + sb.Append(Strings.LogContextPipelineId); + sb.AppendLine(context.PipelineId); + sb.Append(Strings.LogContextCommandName); + sb.AppendLine(context.CommandName); + sb.Append(Strings.LogContextCommandType); + sb.AppendLine(context.CommandType); + sb.Append(Strings.LogContextScriptName); + sb.AppendLine(context.ScriptName); + sb.Append(Strings.LogContextCommandPath); + sb.AppendLine(context.CommandPath); + sb.Append(Strings.LogContextSequenceNumber); + sb.AppendLine(context.SequenceNumber); + sb.Append(Strings.LogContextUser); + sb.AppendLine(context.User); + sb.Append(Strings.LogContextConnectedUser); + sb.AppendLine(context.ConnectedUser); + sb.Append(Strings.LogContextShellId); + sb.AppendLine(context.ShellId); + + return sb.ToString(); + } + + #endregion } /// diff --git a/src/System.Management.Automation/resources/EventResource.resx b/src/System.Management.Automation/resources/EventResource.resx new file mode 100644 index 00000000000..5099674c6eb --- /dev/null +++ b/src/System.Management.Automation/resources/EventResource.resx @@ -0,0 +1,630 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + A message was not found for event id PowerShell-Core-Instrumentation.man. + + + Scheduled Job {0} started at {1} %n + + + Scheduled Job {0} completed at {1} with state {2} %n + + + Scheduled Job Exception {0}: %n Message: {1} %n StackTrace: {2} %n InnerException: {3} %n + + + Workflow plugin loaded. %n %t EndpointName: {0} %n %t User: {1} %n %t HostingMode: {2} %n %t Protocol: {3} %n %t Configuration: %n {4} + + + Workflow execution started. %n %t WorkflowId: {0} %n %t ManagedNodes: {1} + + + Workflow state changed. %n %t WorkflowId: {0} %n %t NewState: {1} %n %t OldState: {2} + + + Workflow plugin has been requested for a shutdown. %n %t EndpointName: {0} + + + Workflow plugin restarted. %n %t EndpointName: {0} + + + Workflow is resuming. %n %t WorkflowId: {0} + + + A quota limit that was set for the endpoint was exceeded. %n %t EndpointName: {0} %n %t ConfigName: {1} %n %t AllowedValue: {2} %n %t ValueInQuestion: {3} + + + Workflow has resumed. %n %t WorkflowId: {0} + + + Workflow runspace pool was created. %n %t WorkflowId: {0} %n %t ManagedNode: {1} + + + Activity was queued for execution. %n %t WorkflowId: {0} %n %t ActivityName: {1} + + + Activity execution started. %n %t ActivityName: {0} %n %t ActivityTypeName: {1} + + + Workflow is being imported from a XAML file. %n %t WorkflowId: {0} %n %t XamlFile: {1} + + + Workflow has been imported from a XAML file. %n %t WorkflowId: {0} %n %t XamlFile: {1} + + + Workflow could not be imported from a XAML file because of an error. %n %t WorkflowId: {0} %n %t ErrorDescription: {1} + + + Workflow validation started. %n %t WorkflowId: {0} + + + Workflow validation succeeded. %n %t WorkflowId: {0} + + + Workflow validation failed with error. %n %t WorkflowId: {0} + + + Workflow activity validated. %n %t WorkflowId: {0} %n %t ActivityDisplayName: {1} %n %t ActivityTypeName: {2} + + + Workflow activity could not be validated. %n %t WorkflowId: {0} %n %t ActivityDisplayName: {1} %n %t ActivityTypeName: {2} + + + Activity execution failed. %n %t WorkflowId: {0} %n %t ActivityName: {1} %n %t FailureDescription: {2} + + + Runspace availability changed. %n %t RunspaceId: {0} %n %t Availability: {1} + + + Runspace state changed. %n %t RunspaceId: {0} %n %t NewState: {1} %n %t OldState: {2} + + + Workflow loaded for execution. %n %t WorkflowId: {0} + + + Workflow unloaded. %n %t WorkflowId: {0} + + + Workflow execution cancelled. %n %t WorkflowId: {0} + + + Workflow execution aborted. %n %t WorkflowId: {0} + + + Workflow cleanup operation executed. %n %t WorkflowId: {0} + + + Persisted workflow loaded from disk. %n %t WorkflowId: {0} %n %t Path: {1} + + + Workflow data was deleted from disk. %n %t WorkflowId: {0} %n %t Path: {1} + + + Starting remove job. %n %t JobId: {0} + + + Job state changed. %n %t JobId: {0} %n %t WorkflowId: {1} %n %t NewState: {2} %n %t OldState: {3} + + + Job error. %n %t JobId: {0} %n %t WorkflowId: {1} %n %t ErrorDescription: {2} + + + Job created for workflow (child job). %n %t ParentJobId: {0} %n %t ChildJobId: {1} %n %t ChildWorkflowId: {2} + + + Parent job created for workflow. %n %t JobId: {0} + + + All required jobs were created for workflow execution. %n %t JobId: {0} %n %t WorkflowId: {1} + + + Child job removed for workflow. %n %t ParentJobId: {0} %n %t ChildJobId: {1} %n %t WorkflowId: {2} + + + An error occurred while removing job. %n %t ParentJobId: {0} %n %t ChildJobId: {1} %n %t WorkflowId: {2} %n %t Error: {3} + + + Loading workflow for execution. %n %t WorkflowId: {0} + + + Workflow execution finished. %n %t WorkflowId: {0} + + + Cancelling workflow execution. %n %t WorkflowId: {0} + + + Aborting workflow execution. %n %t WorkflowId: {0} %n %t Reason: {1} + + + Unloading workflow. %n %t WorkflowId: {0} + + + Forced workflow shutdown started. %n %t WorkflowId: {0} + + + Forced workflow shutdown finished. %n %t WorkflowId: {0} + + + An error occurred while forcefully shutting down a workflow. %n %t WorkflowId: {0} %n %t ErrorDescription: {1} + + + Persisting workflow to disk. %n %t WorkflowId: {0} %n %t PersistPath: {1} + + + Workflow persisted to disk. %n %t WorkflowId: {0} + + + Activity execution finished. %n %t ActivityName: {0} + + + Workflow execution error. %n %t WorkflowId: {0} %n %t ErrorDescription: {1} + + + A new PowerShell endpoint was registered. %n %t EndpointName: {0} %n %t EndpointType: {1} %n %t RegisteredBy: {2} + + + Endpoint configuration modified. %n %t EndpointName: {0} %n %t ModifiedBy: {1} + + + Endpoint configuration unregistered. %n %t EndpointName: {0} %n %t UnregisteredBy: {1} + + + Endpoint configuration disabled. %n %t EndpointName: {0} %n %t DisabledBy: {1} + + + Endpoint configuration enabled. %n %t EndpointName: {0} %n %t EnabledBy: {1} + + + Out of process runspace started. %n %t Command: {0} + + + Parameter splatting was performed during workflow execution. %n %t Parameters: {0} %n %t Computers: {1} + + + Workflow engine started. %n %t EndpointName: {0} + + + Workflow manager instantiated with %n %t CheckpointPath: {0} %n %t ConfigProviderId: {1} %n %t UserName: {2} %n %t Path: {3} + + + Computer Name $null or . resolve to LocalHost + + + Resolving to default scheme http + + + Remote shell name resolved to default PowerShellCore + + + {2}%n%nContext:%n{0}%n%nUser Data:%n{1}%n + + + {2}%n%nContext:%n{0}%n%nUser Data:%n{1}%n + + + {2}%n%nContext:%n{0}%n%nUser Data:%n{1}%n + + + {2}%n%nContext:%n{0}%n%nUser Data:%n{1}%n + + + Creating Scriptblock text ({0} of {1}):%n{2}%n%nScriptBlock ID: {3}%nPath: {4} + + + Started invocation of ScriptBlock ID: {0}%nRunspace ID: {1} + + + Completed invocation of ScriptBlock ID: {0}%nRunspace ID: {1} + + + {2}%n%nContext:%n{0}%n%nUser Data:%n{1}%n + + + {2}%n%nContext:%n{0}%n%nUser Data:%n{1}%n + + + {2}%n%nContext:%n{0}%n%nUser Data:%n{1}%n + + + {2}%n%nContext:%n{0}%n%nUser Data:%n{1}%n + + + Correlating activity id's. %n %t CurrentActivityId: {0} %n %t ParentActivityId: {1} + + + Class Name = {0}%nMethod Name = {1}%nWorkflow GUID = {2}%nMessage = {3}%n{4}%nActivity Name = {5}%nActivity GUID = {6}%nParameters = {7} + + + Creating Runspace object %n %t Instance Id: {0} + + + Creating RunspacePool object %n %t InstanceId {0} %n %t MinRunspaces {1} %n %t MaxRunspaces {2} + + + Opening RunspacePool + + + Modifying activity Id and correlating + + + Runspace state changed to {0} + + + Attempting session creation retry {0} for error code {1} on session Id {2} + + + Windows PowerShell has started an IPC listening thread on process: {0} in AppDomain: {1}. + + + Windows PowerShell has ended an IPC listening thread on process: {0} in AppDomain: {1}. + + + An error has occurred in Windows PowerShell IPC listening thread on process: {0} in AppDomain: {1}. Error Message: {2}. + + + Windows PowerShell IPC connect on process: {0} in AppDomain: {1} for User: {2}. + + + Windows PowerShell IPC disconnect on process: {0} in AppDomain: {1} for User: {2}. + + + Port resolved to {0} + + + AppName resolved to {0} + + + ComputerName resolved to {0} + + + Scheme is {0} + + + Test analytic message + + + Connection Paramters are %n Connection URI: {0} %n Resource URI: {1} %n User: {2} %n OpenTimeout: {3} %n IdleTimeout: {4} %n CancelTimeout: {5} %n AuthenticationMechanism: {6} %n Thumb Print: {7} %n MaxUriRedirectionCount: {8} %n MaxReceivedDataSizePerCommand: {0}0 %n MaxReceivedObjectSize: {0}1 + + + Modifying activity Id and correlating + + + Received object with Runspace Id: {0} Command Id: {1} Destination: {2} DataType: {3} TargetInterface: {4} + + + An unhandled exception occurred in the appdomain. %nException Type: {0} %nException Message: {1} %nException StackTrace: {2} + + + Runspace Id: {0} Pipeline Id: {1}. WSMan reported an error with error code: {2}. %n Error message: {3} %n StackTrace: {4} + + + An unhandled exception occurred in the appdomain. %nException Type: {0} %nException Message: {1} %nException StackTrace: {2} + + + Runspace Id: {0} Pipeline Id: {1}. WSMan reported an error with error code: {2}. %n Error message: {3} %n StackTrace: {4} + + + Runspace Id {0}. Establishing a connection using WSMan Create Shell + + + Runspace Id {0}. Callback received for WSMan Create Shell + + + Runspace Id: {0}. Closing shell using WSManCloseShell + + + Runspace Id: {0}. Callback received for WSManCloseShell + + + Runspace Id: {0} Pipeline Id: {1}. Sending data of size {2} + + + Runspace Id: {0} Pipeline Id: {1}. Callback received for WSManSendShellInputEx + + + Runspace Id: {0} Pipeline Id: {1}. Placing Receive request using WSManReceiveShellOutputEx + + + Runspace Id: {0} Pipeline Id: {1}. Received Data of size {2}. + + + Runspace Id {0} Pipeline Id {1}. Establishing a command connection using WSManRunShellCommandEx + + + Runspace Id {0} Pipeline Id {1}. Callback received for command connection + + + Runspace Id: {0} Pipeline Id {1}. Closing transport for command + + + Runspace Id: {0} Pipeline Id {1}. Callback received for command close + + + Runspace Id: {0} Pipeline Id {1}. Sending signal with code {2} using WSManSignalShellEx + + + Runspace Id: {0} Pipeline Id {1}. Callback received for WSManSignalShellEx + + + Runspace Id: {0}. Connection is getting redirected to Uri: {1} + + + Runspace Id: {0} Pipeline Id: {1}. Server is sending data of size {2} to client. DataType: {3} TargetInterface: {4} + + + Request {0}. Creating a server remote session. UserName: {1} Custome Shell Id: {2} + + + Reporting context for request: {0} Context Reported: {0} + + + Reporting operation complete for request: {0} %n Error Code: {1} %n Error Message: {2} %n StackTrace: {3} + + + Shell Context {0}. Request Id {1}. Creating a commonad session for running a command. + + + Shell Context {0} Command Context {1} Request Id {2}. Stopping command. + + + Shell Context {0} Command Context {1} Request Id {2}. Received data from client. + + + Shell Context {0} Command Context {1} Request Id {2}. Client sent a receive request so that server can send data. + + + Shell Context {0} Command Context {1} IsReceiveOperation {2}. Got close operation request. + + + Loading assembly {0} for custom shell with shell Id {1} + + + Loading type {0} for custom shell with shell Id {1} + + + Received remoting fragment. %n %t Object Id: {0} %n %t Fragment Id: {1} %n %t Start Flag: {2} %n %t End Flag: {3} %n %t Payload Length: {4} %n %t Payload Data: {5} + + + Sent remoting fragment. %n %t Object Id: {0} %n %t Fragment Id: {1} %n %t Start Flag: {2} %n %t End Flag: {3} %n %t Payload Length: {4} %n %t Payload Data: {5} + + + Shutting down winrm service. + + + Successfully rehydrated an object. %n %t Deserialized type name: {0} %n %t Rehydrated by casting to type: {1} %n %t Rehydrated object is of type: {2} + + + Failed to rehydrated an object. %n %t Deserialized type name: {0} %n %t Rehydrated by casting to type: {1} %n %t Type cast exception: {2} %n %t Type cast inner exception: {3} + + + Serialization depth has been overriden. %n %t Serialized type name: {0} %n %t Original depth: {1} %n %t Overriden depth: {2} %n %t Current depth below top level: {3} + + + Serialization mode has been overriden. %n %t Serialized type name: {0} %n %t Overriden mode: {1} + + + Serialization of a script property has been skipped, because there is no runspace to use for evaluation of the property. %n %t Property name: {0} %n %t Property owner's type name: {1} %n %t Getter script: {2} + + + Serialization of a property has been skipped, because property getter failed. %n %t Property name: {0} %n %t Property owner's type name: {1} %n %t Exception from property getter: {2} %n %t Inner exception from property getter: {3} + + + Serialization of an enumerable object might not be complete, because object being enumerated threw an exception. %n %t Type of object being enumerated: {0} %n %t Exception: {1} + + + Serialization called object's ToString method which failed. %n %t Type of object: {0} %n %t Exception: {1} + + + Maximum depth below top level has been reached, forcing object to be serialized as strings. %n %t Object type at max depth: {0} %n %t Property name at max depth: {1} %n %t Depth: {2} + + + XmlException has been thrown by the deserializer (most likely indicating incorrect clixml format). %n %t Line number: {0} Line position: {1} %n %t Exception: {2} + + + Serialization of specified properties failed, because one of the specified properties was missing. %n %t Type of object: {0} %n %t Property name: {1} + + + PowerShell console is starting up + + + PowerShell console is ready for user input + + + {0} + + + Tracing ErrorRecord: %n Message: {0} %n CategoryInfo.Category: {1} %n CategoryInfo.Reason : {2} %n CategoryInfo.TargetName : {3} %n FullyQualifiedErrorId: {4} %n Exception Details: %n Message : {5} %n Stack Trace: {6} %n InnerException {7} %n + + + Exception: %n Message: {0} %n StackTrace: {1} %n InnerException : {2} %n + + + Tracing PSObject + + + Tracing Job: %n Id: {0} %n InstanceId: {1} %n Name: {2} %n Location: {3} %n State: {4} %n Command: {5} %n + + + Trace Information: %n {0} + + + Trace Information: %n {0} {1} + + + BEGIN ImportWorkflowCommand::StartWorkflowApplication. Starting invocation of workflow function. Tracking Guid {0} + + + END ImportWorkflowCommand::StartWorkflowApplication. Ending invocation of workflow function. Tracking Guid {0} + + + BEGIN Creating new job in ImportWorkflowCommand::StartWorkflowApplication. Tracking Guid {0} + + + END Creating new job in ImportWorkflowCommand::StartWorkflowApplication. Tracking Guid {0} + + + END Creating new job in ImportWorkflowCommand::StartWorkflowApplication. Tracking Guid {0} : ContainerParentJob Guid {1} + + + BEGIN JobLogic ContainerParentJob Guid {0} + + + END JobLogic ContainerParentJob Guid {0} + + + BEGIN WorkflowExecution ContainerParentJob Guid {0} + + + END WorkflowExecution ContainerParentJob Guid {0} + + + WorkflowJob with Guid {0} added to ContainerParentJob with Guid {1} + + + ProxyJob with Guid {0} associated with remote ContainerParentJob with Guid {1} + + + BEGIN Execution of ContainerParentJob with Guid {0} + + + END Execution of ContainerParentJob with Guid {0} + + + BEGIN Execution of Proxy Job with Guid {0} + + + END Execution of Proxy Job with Guid {0} + + + BEGIN StateChanged event handler for Proxy Job with Guid {0} + + + END StateChanged event handler for Proxy Job with Guid {0} + + + BEGIN StateChanged event handler for Proxy Child Job with Guid {0} + + + END StateChanged event handler for Proxy Child Job with Guid {0} + + + BEGIN Running garbage collection + + + END Running garbage collection + + + Persistence store has reached its maximum specified size + + + Windows PowerShell ISE has started to run script file {0}. + + + Windows PowerShell ISE has started to run a user-selected script from file {0}. + + + Windows PowerShell ISE is stopping the current command. + + + Windows PowerShell ISE is resuming the debugger. + + + Windows PowerShell ISE is stopping the debugger. + + + Windows PowerShell ISE is stepping into debugging. + + + Windows PowerShell ISE is stepping over debugging. + + + Windows PowerShell ISE is stepping out of debugging. + + + Windows PowerShell ISE is enabling all breakpoints. + + + Windows PowerShell ISE is disabling all breakpoints. + + + Windows PowerShell ISE is removing all breakpoints. + + + Windows PowerShell ISE is setting the breakpoint at line #: {0} of file {1}. + + + Windows PowerShell ISE is removing the breakpoint on line #: {0} of file {1}. + + + Windows PowerShell ISE is enabling the breakpoint on line #: {0} of file {1}. + + + Windows PowerShell ISE is disabling the breakpoint on line #: {0} of file {1}. + + + Windows PowerShell ISE has hit a breakpoint on line #: {0} of file {1}. + + diff --git a/src/System.Management.Automation/utils/PowerShellETWTracer.cs b/src/System.Management.Automation/utils/PowerShellETWTracer.cs index 06e9bf39319..39990d8a30d 100644 --- a/src/System.Management.Automation/utils/PowerShellETWTracer.cs +++ b/src/System.Management.Automation/utils/PowerShellETWTracer.cs @@ -809,7 +809,7 @@ public sealed class PowerShellChannelWriter : BaseChannelWriter /* * Making the provider static to reduce the number of buffers needed to 1. * */ - private static readonly EventProvider _provider = new EventProvider(new Guid("A0C1853B-5C40-4b15-8766-3CF1C58F985A")); + private static readonly EventProvider _provider = new EventProvider(PSEtwLogProvider.ProviderGuid); private bool disposed; private PowerShellTraceKeywords _keywords; diff --git a/src/System.Management.Automation/utils/tracing/EtwActivity.cs b/src/System.Management.Automation/utils/tracing/EtwActivity.cs index 45794cc00bd..75db5129b6c 100644 --- a/src/System.Management.Automation/utils/tracing/EtwActivity.cs +++ b/src/System.Management.Automation/utils/tracing/EtwActivity.cs @@ -251,7 +251,6 @@ public void Callback(IAsyncResult asyncResult) } } - private static Guid powerShellProviderId = Guid.Parse("A0C1853B-5C40-4b15-8766-3CF1C58F985A"); private static Dictionary providers = new Dictionary(); private static object syncLock = new object(); @@ -431,7 +430,7 @@ protected virtual Guid ProviderId { get { - return powerShellProviderId; + return PSEtwLogProvider.ProviderGuid; } } diff --git a/src/System.Management.Automation/utils/tracing/PSEtwLog.cs b/src/System.Management.Automation/utils/tracing/PSEtwLog.cs index c2f449862f4..8ba057e94bf 100644 --- a/src/System.Management.Automation/utils/tracing/PSEtwLog.cs +++ b/src/System.Management.Automation/utils/tracing/PSEtwLog.cs @@ -1,4 +1,3 @@ -#if !UNIX // // Copyright (c) Microsoft Corporation. All rights reserved. // @@ -13,14 +12,22 @@ namespace System.Management.Automation.Tracing /// internal static class PSEtwLog { +#if UNIX + private static PSSysLogProvider provider; +#else private static PSEtwLogProvider provider; +#endif /// /// Class constructor /// static PSEtwLog() { +#if UNIX + provider = new PSSysLogProvider(); +#else provider = new PSEtwLogProvider(); +#endif } /// @@ -311,6 +318,3 @@ internal static void WriteTransferEvent(Guid parentActivityId) } } } - - -#endif diff --git a/src/System.Management.Automation/utils/tracing/PSEtwLogProvider.cs b/src/System.Management.Automation/utils/tracing/PSEtwLogProvider.cs old mode 100644 new mode 100755 index 01b3b636bcb..574508a004c --- a/src/System.Management.Automation/utils/tracing/PSEtwLogProvider.cs +++ b/src/System.Management.Automation/utils/tracing/PSEtwLogProvider.cs @@ -15,38 +15,15 @@ namespace System.Management.Automation.Tracing internal class PSEtwLogProvider : LogProvider { private static EventProvider etwProvider; - private static readonly string PowerShellEventProviderGuid = "A0C1853B-5C40-4b15-8766-3CF1C58F985A"; + internal static readonly Guid ProviderGuid = new Guid("F90714A8-5509-434A-BF6D-B1624C8A19A2"); private static EventDescriptor _xferEventDescriptor = new EventDescriptor(0x1f05, 0x1, 0x11, 0x5, 0x14, 0x0, (long)0x4000000000000000); - private static class Strings - { - // The strings are stored in a different class to defer loading the resources until as late - // as possible, e.g. if logging is never on, these strings won't be loaded. - internal static readonly string LogContextSeverity = EtwLoggingStrings.LogContextSeverity; - internal static readonly string LogContextHostName = EtwLoggingStrings.LogContextHostName; - internal static readonly string LogContextHostVersion = EtwLoggingStrings.LogContextHostVersion; - internal static readonly string LogContextHostId = EtwLoggingStrings.LogContextHostId; - internal static readonly string LogContextHostApplication = EtwLoggingStrings.LogContextHostApplication; - internal static readonly string LogContextEngineVersion = EtwLoggingStrings.LogContextEngineVersion; - internal static readonly string LogContextRunspaceId = EtwLoggingStrings.LogContextRunspaceId; - internal static readonly string LogContextPipelineId = EtwLoggingStrings.LogContextPipelineId; - internal static readonly string LogContextCommandName = EtwLoggingStrings.LogContextCommandName; - internal static readonly string LogContextCommandType = EtwLoggingStrings.LogContextCommandType; - internal static readonly string LogContextScriptName = EtwLoggingStrings.LogContextScriptName; - internal static readonly string LogContextCommandPath = EtwLoggingStrings.LogContextCommandPath; - internal static readonly string LogContextSequenceNumber = EtwLoggingStrings.LogContextSequenceNumber; - internal static readonly string LogContextUser = EtwLoggingStrings.LogContextUser; - internal static readonly string LogContextConnectedUser = EtwLoggingStrings.LogContextConnectedUser; - internal static readonly string LogContextTime = EtwLoggingStrings.LogContextTime; - internal static readonly string LogContextShellId = EtwLoggingStrings.LogContextShellId; - } - /// /// Class constructor /// static PSEtwLogProvider() { - etwProvider = new EventProvider(new Guid(PowerShellEventProviderGuid)); + etwProvider = new EventProvider(ProviderGuid); } /// @@ -269,137 +246,6 @@ internal override bool UseLoggingVariables() return false; } - /// - /// Gets PSLogUserData from execution context - /// - /// - /// - private static string GetPSLogUserData(ExecutionContext context) - { - if (context == null) - { - return String.Empty; - } - - object logData = context.GetVariableValue(SpecialVariables.PSLogUserDataPath); - - if (logData == null) - { - return String.Empty; - } - - return logData.ToString(); - } - - /// - /// Appends exception information - /// - /// string builder - /// exception - internal static void AppendException(StringBuilder sb, Exception except) - { - sb.AppendLine(StringUtil.Format(EtwLoggingStrings.ErrorRecordMessage, except.Message)); - - IContainsErrorRecord ier = except as IContainsErrorRecord; - - if (ier != null) - { - ErrorRecord er = ier.ErrorRecord; - - if (er != null) - { - sb.AppendLine(StringUtil.Format(EtwLoggingStrings.ErrorRecordId, er.FullyQualifiedErrorId)); - - ErrorDetails details = er.ErrorDetails; - - if (details != null) - { - sb.AppendLine(StringUtil.Format(EtwLoggingStrings.ErrorRecordRecommendedAction, details.RecommendedAction)); - } - } - } - } - - /// - /// Appends additional information - /// - /// string builder - /// additional information - private static void AppendAdditionalInfo(StringBuilder sb, Dictionary additionalInfo) - { - if (additionalInfo != null) - { - foreach (KeyValuePair value in additionalInfo) - { - sb.AppendLine(StringUtil.Format("{0} = {1}", value.Key, value.Value)); - } - } - } - - /// - /// Gets PSLevel from severity - /// - /// error severity - /// PS log level - private static PSLevel GetPSLevelFromSeverity(string severity) - { - switch (severity) - { - case "Critical": - case "Error": - return PSLevel.Error; - case "Warning": - return PSLevel.Warning; - default: - return PSLevel.Informational; - } - } - - /// - /// Converts log context to string - /// - /// log context - /// string representation - private static string LogContextToString(LogContext context) - { - StringBuilder sb = new StringBuilder(); - - sb.Append(Strings.LogContextSeverity); - sb.AppendLine(context.Severity); - sb.Append(Strings.LogContextHostName); - sb.AppendLine(context.HostName); - sb.Append(Strings.LogContextHostVersion); - sb.AppendLine(context.HostVersion); - sb.Append(Strings.LogContextHostId); - sb.AppendLine(context.HostId); - sb.Append(Strings.LogContextHostApplication); - sb.AppendLine(context.HostApplication); - sb.Append(Strings.LogContextEngineVersion); - sb.AppendLine(context.EngineVersion); - sb.Append(Strings.LogContextRunspaceId); - sb.AppendLine(context.RunspaceId); - sb.Append(Strings.LogContextPipelineId); - sb.AppendLine(context.PipelineId); - sb.Append(Strings.LogContextCommandName); - sb.AppendLine(context.CommandName); - sb.Append(Strings.LogContextCommandType); - sb.AppendLine(context.CommandType); - sb.Append(Strings.LogContextScriptName); - sb.AppendLine(context.ScriptName); - sb.Append(Strings.LogContextCommandPath); - sb.AppendLine(context.CommandPath); - sb.Append(Strings.LogContextSequenceNumber); - sb.AppendLine(context.SequenceNumber); - sb.Append(Strings.LogContextUser); - sb.AppendLine(context.User); - sb.Append(Strings.LogContextConnectedUser); - sb.AppendLine(context.ConnectedUser); - sb.Append(Strings.LogContextShellId); - sb.AppendLine(context.ShellId); - - return sb.ToString(); - } - /// /// Writes a single event /// diff --git a/src/System.Management.Automation/utils/tracing/PSSysLogProvider.cs b/src/System.Management.Automation/utils/tracing/PSSysLogProvider.cs new file mode 100755 index 00000000000..3f316b1e55a --- /dev/null +++ b/src/System.Management.Automation/utils/tracing/PSSysLogProvider.cs @@ -0,0 +1,337 @@ +#if UNIX +// +// Copyright (C) Microsoft. All rights reserved. +// +using System.Diagnostics.Eventing; +using System.Management.Automation.Internal; +using System.Text; +using System.Collections.Generic; + +namespace System.Management.Automation.Tracing +{ + /// + /// SysLog LogProvider implementation. + /// + internal class PSSysLogProvider : LogProvider + { + private static SysLogProvider s_provider; + + // by default, do not include analytic events + internal const PSKeyword DefaultKeywords = (PSKeyword) (0xFFFFFFFFFFFFFFFF & ~(ulong)PSKeyword.UseAlwaysAnalytic); + + /// + /// Class constructor. + /// + static PSSysLogProvider() + { + s_provider = new SysLogProvider(ConfigPropertyAccessor.Instance.GetSysLogIdentity(), + ConfigPropertyAccessor.Instance.GetLogLevel(), + ConfigPropertyAccessor.Instance.GetLogKeywords(), + ConfigPropertyAccessor.Instance.GetLogChannels()); + } + + /// + /// Defines a thread local StringBuilder for building event payload strings. + /// + /// + /// NOTE: do not access this field directly, use the PayloadBuilder + /// property to ensure correct thread initialization; otherwise, a null reference can occur. + /// + [ThreadStatic] + private static StringBuilder _payloadBuilder; + + private static StringBuilder PayloadBuilder + { + get + { + if (_payloadBuilder == null) + { + // NOTE: Thread static fields must be explicitly initialized for each thread. + _payloadBuilder = new StringBuilder(200); + } + return _payloadBuilder; + } + } + + + + /// + /// Determines whether any session is requesting the specified event from the provider. + /// + /// + /// + /// + /// + /// Typically, a provider does not call this method to determine whether a session requested the specified event; + /// the provider simply writes the event, and ETW determines whether the event is logged to a session. A provider + /// may want to call this function if the provider needs to perform extra work to generate the event. In this case, + /// calling this function first to determine if a session requested the event or not, may save resources and time. + /// + internal bool IsEnabled(PSLevel level, PSKeyword keywords) + { + return s_provider.IsEnabled(level, keywords); + } + + /// + /// Provider interface function for logging health event + /// + /// + /// + /// + /// + /// + internal override void LogEngineHealthEvent(LogContext logContext, int eventId, Exception exception, Dictionary additionalInfo) + { + StringBuilder payload = PayloadBuilder; + payload.Clear(); + + AppendException(payload, exception); + payload.AppendLine(); + AppendAdditionalInfo(payload, additionalInfo); + + WriteEvent(PSEventId.Engine_Health, PSChannel.Operational, PSOpcode.Exception, PSTask.ExecutePipeline, logContext, payload.ToString()); + } + + /// + /// Provider interface function for logging engine lifecycle event + /// + /// + /// + /// + /// + internal override void LogEngineLifecycleEvent(LogContext logContext, EngineState newState, EngineState previousState) + { + if (IsEnabled(PSLevel.Informational, PSKeyword.Cmdlets | PSKeyword.UseAlwaysAnalytic)) + { + StringBuilder payload = PayloadBuilder; + payload.Clear(); + + payload.AppendLine(StringUtil.Format(EtwLoggingStrings.EngineStateChange, previousState.ToString(), newState.ToString())); + + PSTask task = PSTask.EngineStart; + + if (newState == EngineState.Stopped || + newState == EngineState.OutOfService || + newState == EngineState.None || + newState == EngineState.Degraded) + { + task = PSTask.EngineStop; + } + + WriteEvent(PSEventId.Engine_Lifecycle, PSChannel.Analytic, PSOpcode.Method, task, logContext, payload.ToString()); + } + } + + /// + /// Provider interface function for logging command health event + /// + /// + /// + internal override void LogCommandHealthEvent(LogContext logContext, Exception exception) + { + StringBuilder payload = PayloadBuilder; + payload.Clear(); + + AppendException(payload, exception); + + WriteEvent(PSEventId.Command_Health, PSChannel.Operational, PSOpcode.Exception, PSTask.ExecutePipeline, logContext, payload.ToString()); + } + + /// + /// Provider interface function for logging command lifecycle event + /// + /// + /// + /// + internal override void LogCommandLifecycleEvent(Func getLogContext, CommandState newState) + { + if (IsEnabled(PSLevel.Informational, PSKeyword.Cmdlets | PSKeyword.UseAlwaysAnalytic)) + { + LogContext logContext = getLogContext(); + StringBuilder payload = PayloadBuilder; + payload.Clear(); + + 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 pipeline execution detail. + /// + /// + /// + internal override void LogPipelineExecutionDetailEvent(LogContext logContext, List pipelineExecutionDetail) + { + StringBuilder payload = PayloadBuilder; + payload.Clear(); + + if (pipelineExecutionDetail != null) + { + foreach (String detail in pipelineExecutionDetail) + { + payload.AppendLine(detail); + } + } + + WriteEvent(PSEventId.Pipeline_Detail, PSChannel.Operational, PSOpcode.Method, PSTask.ExecutePipeline, logContext, payload.ToString()); + } + + /// + /// Provider interface function for logging provider health event + /// + /// + /// + /// + internal override void LogProviderHealthEvent(LogContext logContext, string providerName, Exception exception) + { + StringBuilder payload = PayloadBuilder; + payload.Clear(); + + AppendException(payload, exception); + payload.AppendLine(); + + Dictionary additionalInfo = new Dictionary(); + + additionalInfo.Add(EtwLoggingStrings.ProviderNameString, providerName); + + AppendAdditionalInfo(payload, additionalInfo); + + WriteEvent(PSEventId.Provider_Health, PSChannel.Operational, PSOpcode.Exception, PSTask.ExecutePipeline, logContext, payload.ToString()); + } + + /// + /// Provider interface function for logging provider lifecycle event + /// + /// + /// + /// + /// + internal override void LogProviderLifecycleEvent(LogContext logContext, string providerName, ProviderState newState) + { + if (IsEnabled(PSLevel.Informational, PSKeyword.Cmdlets | PSKeyword.UseAlwaysAnalytic)) + { + StringBuilder payload = PayloadBuilder; + payload.Clear(); + + payload.AppendLine(StringUtil.Format(EtwLoggingStrings.ProviderStateChange, providerName, newState.ToString())); + + PSTask task = PSTask.ProviderStart; + + if (newState == ProviderState.Stopped) + { + task = PSTask.ProviderStop; + } + + WriteEvent(PSEventId.Provider_Lifecycle, PSChannel.Analytic, PSOpcode.Method, task, logContext, payload.ToString()); + } + } + + /// + /// Provider interface function for logging settings event + /// + /// + /// + /// + /// + /// + internal override void LogSettingsEvent(LogContext logContext, string variableName, string value, string previousValue) + { + if (IsEnabled(PSLevel.Informational, PSKeyword.Cmdlets | PSKeyword.UseAlwaysAnalytic)) + { + StringBuilder payload = PayloadBuilder; + payload.Clear(); + + if (previousValue == null) + { + payload.AppendLine(StringUtil.Format(EtwLoggingStrings.SettingChangeNoPrevious, variableName, value)); + } + else + { + payload.AppendLine(StringUtil.Format(EtwLoggingStrings.SettingChange, variableName, previousValue, value)); + } + + WriteEvent(PSEventId.Settings, PSChannel.Analytic, PSOpcode.Method, PSTask.ExecutePipeline, logContext, payload.ToString()); + } + } + + /// + /// The SysLog provider does not use logging variables + /// + /// + internal override bool UseLoggingVariables() + { + return false; + } + + /// + /// Writes a single event + /// + /// event id + /// + /// + /// + /// log context + /// + internal void WriteEvent(PSEventId id, PSChannel channel, PSOpcode opcode, PSTask task, LogContext logContext, string payLoad) + { + s_provider.Log(id, channel, task, opcode, GetPSLevelFromSeverity(logContext.Severity), DefaultKeywords, + LogContextToString(logContext), + GetPSLogUserData(logContext.ExecutionContext), + payLoad); + } + + /// + /// Writes an event + /// + /// + /// + /// + /// + /// + /// + /// + internal void WriteEvent(PSEventId id, PSChannel channel, PSOpcode opcode, PSLevel level, PSTask task, PSKeyword keyword, params object[] args) + { + s_provider.Log(id, channel, task, opcode, level, keyword, args); + } + + /// + /// Writes an activity transfer event + /// + internal void WriteTransferEvent(Guid parentActivityId) + { + s_provider.LogTransfer(parentActivityId); + } + + /// + /// Sets the activity id for the current thread. + /// + /// the GUID identifying the activity. + internal void SetActivityIdForCurrentThread(Guid newActivityId) + { + s_provider.SetActivity(newActivityId); + } + } +} + +#endif // UNIX diff --git a/src/System.Management.Automation/utils/tracing/SysLogProvider.cs b/src/System.Management.Automation/utils/tracing/SysLogProvider.cs new file mode 100755 index 00000000000..d54392e607a --- /dev/null +++ b/src/System.Management.Automation/utils/tracing/SysLogProvider.cs @@ -0,0 +1,522 @@ +#if UNIX + +using System; +using System.Diagnostics; +using System.Globalization; +using System.Reflection; +using System.Resources; +using System.Runtime.InteropServices; +using System.Text; +using System.Threading; + +using System.Management.Automation.Internal; + +namespace System.Management.Automation.Tracing +{ + /// + /// Encapsulates the message resource and SysLog logging for an ETW event. + /// The other half of the partial class is generated by EtwGen and contains a + /// static dictionary containing the event id mapped to the associated event meta data + /// and resource string reference. + /// + /// + /// This component logs ETW trace events to syslog. + /// The log entries use the following common format + /// (commitId:threadId:channelid) [context] payload + /// Where: + /// commitId: A hash code of the full git commit id string. + /// threadid: The thread identifier of calling code. + /// channelid: The identifier for the output channel. See PSChannel for values. + /// context: Dependent on the type of log entry. + /// payload: Dependent on the type of log entry. + /// Note: + /// commitId, threadId, and eventId are logged as HEX without a leading + /// '0x'. + /// + /// 4 types of log entries are produced. + /// NOTE: Where constant string are logged, the template places the string in + /// double quotes. For example, the GitCommitId log entry uses "GitCommitId" + /// for the context value. + /// + /// Note that the examples illustrate the output from SysLogProvider.Log, + /// Data automatically prepended by syslog, such as timestamp, hostname, ident, + /// and processid are not shown. + /// + /// GitCommitId + /// This is the first log entry for a session. It provides a correlation + /// between the full git commit id string and a hash code used for subsequent + /// log entries. + /// Context: "GitCommitId" + /// Payload: string "Hash:" hashcode as HEX string. + /// For official builds, the GitCommitID is the release tag. For other builds the commit id may include an SHA-1 hash at the + /// end of the release tag. + /// Example 1: Official release + /// (19E1025:3:10) [GitCommitId] v6.0.0-beta.9 Hash:64D0C08D + /// Example 2: Commit id with SHA-1 hash + /// (19E1025:3:10) [GitCommitId] v6.0.0-beta.8-67-gca2630a3dea6420a3cd3914c84a74c1c45311f54 Hash:8EE3A3B3 + /// + /// Transfer + /// A log entry to record a transfer event. + /// Context: "Transfer" + /// The playload is two, space separated string guids, the first being the + /// parent activityid followed by the new activityid. + /// Example: (19E1025:3:10) [Transfer] {de168a71-6bb9-47e4-8712-bc02506d98be} {ab0077f6-c042-4728-be76-f688cfb1b054} + /// + /// Activity + /// A log entry for when activity is set. + /// Context: "Activity" + /// Payload: The string guid of the activity id. + /// Example: (19E1025:3:10) [Activity] {ab0077f6-c042-4728-be76-f688cfb1b054} + /// + /// Event + /// Application logging (Events) + /// Context: EventId:taskname.opcodename.levelname + /// Payload: The event's message text formatted with arguments from the caller. + /// Example: (19E1025:3:10) [Perftrack_ConsoleStartupStart:PowershellConsoleStartup.WinStart.Informational] PowerShell console is starting up + /// + internal class SysLogProvider + { + // Ensure the string pointer is not garbage collected. + static IntPtr _nativeSyslogIdent = IntPtr.Zero; + static NativeMethods.SysLogPriority _facility = NativeMethods.SysLogPriority.Local0; + + byte _channelFilter; + ulong _keywordFilter; + byte _levelFilter; + + /// + /// Initializes a new instance of this class. + /// + /// The log identity name used to identify the application in syslog. + /// The trace lavel to enable. + /// The keywords to enable. + /// The output channels to enable. + public SysLogProvider(string applicationId, PSLevel level, PSKeyword keywords, PSChannel channels) + { + // NOTE: This string needs to remain valid for the life of the process since the underlying API keeps + // a reference to it. + // FUTURE: If logging is redesigned, make these details static or a singleton since there should only be one + // instance active. + _nativeSyslogIdent = Marshal.StringToHGlobalAnsi(applicationId); + NativeMethods.OpenLog(_nativeSyslogIdent, _facility); + _keywordFilter = (ulong)keywords; + _levelFilter = (byte) level; + _channelFilter = (byte) channels; + } + + /// + /// Defines a thread local StringBuilder for building log messages. + /// + /// + /// NOTE: do not access this field directly, use the MessageBuilder + /// property to ensure correct thread initialization; otherwise, a null reference can occur. + /// + [ThreadStatic] + private static StringBuilder _messageBuilder; + + private static StringBuilder MessageBuilder + { + get + { + if (_messageBuilder == null) + { + // NOTE: Thread static fields must be explicitly initialized for each thread. + _messageBuilder = new StringBuilder(200); + } + return _messageBuilder; + } + } + + /// + /// Defines a activity id for the current thread. + /// + /// + /// NOTE: do not access this field directly, use the Activity property + /// to ensure correct thread initialization. + /// + [ThreadStatic] + static Guid? _activity; + + private static Guid Activity + { + get + { + if (_activity.HasValue == false) + { + // NOTE: Thread static fields must be explicitly initialized for each thread. + _activity = Guid.NewGuid(); + } + return _activity.Value; + } + set + { + _activity = value; + } + } + + /// + /// Gets the value indicating if the specified level and keywords are enabled for logging. + /// + /// The PSLevel to check. + /// The PSKeyword to check. + /// true if the specified level and keywords are enabled for logging. + internal bool IsEnabled(PSLevel level, PSKeyword keywords) + { + return ( ((ulong) keywords & _keywordFilter) != 0 && + ((int) level <= _levelFilter) ); + } + + // NOTE: There are a number of places where PowerShell code sends analytic events + // to the operational channel. This is a side-effect of the custom wrappers that + // use flags that are not consistent with the event definition. + // To ensure filtering of analytic events is consistent, both keyword and channel + // filtering is performed to suppress analytic events. + private bool ShouldLog(PSLevel level, PSKeyword keywords, PSChannel channel) + { + return ((_channelFilter & (ulong)channel) != 0 && + IsEnabled(level, keywords)); + } + + #region resource manager + + private static global::System.Resources.ResourceManager _resourceManager; + private static global::System.Globalization.CultureInfo _resourceCulture; + + private static global::System.Resources.ResourceManager ResourceManager + { + get + { + if (object.ReferenceEquals(_resourceManager, null)) + { + _resourceManager = new global::System.Resources.ResourceManager("System.Management.Automation.resources.EventResource", typeof(EventResource).GetTypeInfo().Assembly); + } + return _resourceManager; + } + } + + /// + /// Overrides the current threads CurrentUICulture property for all + /// resource lookups using this strongly typed resource class. + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + internal static global::System.Globalization.CultureInfo Culture + { + get + { + return _resourceCulture; + } + set + { + _resourceCulture = value; + } + } + + private static string GetResourceString(string resourceName) + { + string value = ResourceManager.GetString(resourceName, Culture); + if (string.IsNullOrEmpty(value)) + { + value = string.Format(CultureInfo.InvariantCulture, "Unknown resource: {0}", resourceName); + Diagnostics.Assert(false, value); + } + return value; + } + + #endregion resource manager + + /// + /// Gets the EventMessage for a given event. + /// + /// The StringBuilder to append. + /// The id of the event to retrieve. + /// An array of zero or more payload objects. + private static void GetEventMessage(StringBuilder sb, PSEventId eventId, params object[] args ) + { + int parameterCount; + string resourceName = EventResource.GetMessage((int) eventId, out parameterCount); + + if (resourceName == null) + { + // If an event id was specified that is not found in the event resource lookup table, + // use a placeholder message that includes the event id. + resourceName = EventResource.GetMissingEventMessage(out parameterCount); + Diagnostics.Assert(false, sb.ToString()); + args = new object[] {eventId}; + } + + string resourceValue = GetResourceString(resourceName); + if (parameterCount > 0) + { + sb.AppendFormat(resourceValue, args); + } + else + { + sb.Append(resourceValue); + } + } + + #region logging + + // maps a LogLevel to an associated SysLogPriority. + static NativeMethods.SysLogPriority[] _levels = + { + NativeMethods.SysLogPriority.Info, + NativeMethods.SysLogPriority.Critical, + NativeMethods.SysLogPriority.Error, + NativeMethods.SysLogPriority.Warning, + NativeMethods.SysLogPriority.Info, + NativeMethods.SysLogPriority.Info + }; + + /// + /// Logs a activity transfer. + /// + /// The parent activity id. + public void LogTransfer(Guid parentActivityId) + { + // NOTE: always log + int threadId = Thread.CurrentThread.ManagedThreadId; + string message = string.Format(CultureInfo.InvariantCulture, + "({0}:{1:X}:{2:X}) [Transfer]:{3} {4}", + PSVersionInfo.GitCommitId, threadId, PSChannel.Operational, + parentActivityId.ToString("B"), + Activity.ToString("B")); + + NativeMethods.SysLog(NativeMethods.SysLogPriority.Info, message); + } + + /// + /// Logs the activity identifier for the current thread. + /// + /// The Guid activity identifier. + public void SetActivity(Guid activity) + { + int threadId = Thread.CurrentThread.ManagedThreadId; + Activity = activity; + + // NOTE: always log + string message = string.Format(CultureInfo.InvariantCulture, + "({0:X}:{1:X}:{2:X}) [Activity] {3}", + PSVersionInfo.GitCommitId, threadId, PSChannel.Operational, activity.ToString("B")); + NativeMethods.SysLog(NativeMethods.SysLogPriority.Info, message); + } + + /// + /// Writes a log entry. + /// + /// The event id of the log entry. + /// The channel to log. + /// The task for the log entry. + /// The operation for the log entry. + /// The logging level. + /// The keyword(s) for the event. + /// The payload for the log message. + public void Log(PSEventId eventId, PSChannel channel, PSTask task, PSOpcode opcode, PSLevel level, PSKeyword keyword, params object[] args) + { + if (ShouldLog(level, keyword, channel)) + { + int threadId = Thread.CurrentThread.ManagedThreadId; + + StringBuilder sb = MessageBuilder; + sb.Clear(); + + // add the message preamble + sb.AppendFormat(CultureInfo.InvariantCulture, + "({0}:{1:X}:{2:X}) [{3:G}:{4:G}.{5:G}.{6:G}] ", + PSVersionInfo.GitCommitId, threadId, channel, eventId, task, opcode, level); + + // add the message + GetEventMessage(sb, eventId, args); + + NativeMethods.SysLogPriority priority; + if ((int) level <= _levels.Length) + { + priority = _levels[(int)level]; + } + else + { + priority = NativeMethods.SysLogPriority.Info; + } + // log it. + NativeMethods.SysLog(priority, sb.ToString()); + } + } + + #endregion logging + } + + internal enum LogLevel : uint + { + Always = 0, + Critical = 1, + Error = 2, + Warning = 3, + Information = 4, + Verbose = 5 + } + + internal static class NativeMethods + { + /// + /// Write a message to the system logger, which in turn writes the message to the system console, log files, etc. + /// See man 3 syslog for more info. + /// + /// + /// The OR of a priority and facility in the SysLogPriority enum indicating the the priority and facility of the log entry. + /// + /// The message to put in the log entry. + [DllImport("psl-native", CharSet = CharSet.Ansi, EntryPoint = "Native_SysLog")] + internal static extern void SysLog(SysLogPriority priority, string message); + + [DllImport("psl-native", CharSet = CharSet.Ansi, EntryPoint = "Native_OpenLog")] + internal static extern void OpenLog(IntPtr ident, SysLogPriority facility); + + [DllImport("psl-native", EntryPoint = "Native_CloseLog")] + internal static extern void CloseLog(); + + [Flags] + internal enum SysLogPriority : uint + { + // Priorities enum values. + + /// + /// System is unusable + /// + Emergency = 0, + + /// + /// Action must be taken immediately + /// + Alert = 1, + + /// + /// Critical conditions + /// + Critical = 2, + + /// + /// Error conditions + /// + Error = 3, + + /// + /// Warning conditions + /// + Warning = 4, + + /// + /// Normal but significant condition + /// + Notice = 5, + + /// + /// Informational + /// + Info = 6, + + /// + /// Debug-level messages + /// + Debug = 7, + + // Facility enum values. + + /// + /// Kernel messages + /// + Kernel = (0<<3), + + /// + /// Random user-level messages + /// + User = (1<<3), + + /// + /// Mail system + /// + Mail = (2<<3), + + /// + /// System daemons + /// + Daemon = (3<<3), + + /// + /// Authorization messages + /// + Authorization = (4<<3), + + /// + /// Messages generated internally by syslogd + /// + Syslog = (5<<3), + + /// + /// Line printer subsystem + /// + Lpr = (6<<3), + + /// + /// Network news subsystem + /// + News = (7<<3), + + /// + /// UUCP subsystem + /// + Uucp = (8<<3), + + /// + /// Clock daemon + /// + Cron = (9<<3), + + /// + /// Security/authorization messages (private) + /// + Authpriv = (10<<3), + + /// + /// FTP daemon + /// + Ftp = (11<<3), + + // Reserved for system use + + /// + /// Reserved for local use + /// + Local0 = (16<<3), + /// + /// Reserved for local use + /// + Local1 = (17<<3), + /// + /// Reserved for local use + /// + Local2 = (18<<3), + /// + /// Reserved for local use + /// + Local3 = (19<<3), + /// + /// Reserved for local use + /// + Local4 = (20<<3), + /// + /// Reserved for local use + /// + Local5 = (21<<3), + /// + /// Reserved for local use + /// + Local6 = (22<<3), + /// + /// Reserved for local use + /// + Local7 = (23<<3), + } + } +} + +#endif // UNIX diff --git a/tools/ResxGen/PowerShell-Core-Instrumentation.man b/tools/ResxGen/PowerShell-Core-Instrumentation.man new file mode 100644 index 00000000000..2fad01ea51c --- /dev/null +++ b/tools/ResxGen/PowerShell-Core-Instrumentation.man @@ -0,0 +1,5635 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + false + + 15728640 + + + + + + true + + 1048985600 + + + + 64 + + + + + + true + + 1048985600 + + + + 64 + + + + + + true + + 1048985600 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +