コード例 #1
0
ファイル: LogProvider.cs プロジェクト: 40a/PowerShell
 /// <summary>
 /// Provider interface function for logging provider health event
 /// </summary>
 /// <param name="logContext"></param>
 /// <param name="providerName"></param>
 /// <param name="exception"></param>
 /// 
 internal abstract void LogProviderHealthEvent(LogContext logContext, string providerName, Exception exception);
コード例 #2
0
ファイル: EventLogLogProvider.cs プロジェクト: 40a/PowerShell
 private static EventLogEntryType GetEventLogEntryType(LogContext logContext)
 {
     switch (logContext.Severity)
     {
         case "Critical":
         case "Error":
             return EventLogEntryType.Error;
         case "Warning":
             return EventLogEntryType.Warning;
         default:
             return EventLogEntryType.Information;
     }
 }
コード例 #3
0
ファイル: LogProvider.cs プロジェクト: 40a/PowerShell
 /// <summary>
 /// Provider interface function for logging health event
 /// </summary>
 /// <param name="logContext"></param>
 /// <param name="eventId"></param>
 /// <param name="exception"></param>
 /// <param name="additionalInfo"></param>
 /// 
 internal abstract void LogEngineHealthEvent(LogContext logContext, int eventId, Exception exception, Dictionary<String, String> additionalInfo);
コード例 #4
0
ファイル: LogProvider.cs プロジェクト: 40a/PowerShell
 /// <summary>
 /// Provider interface function for logging command health event
 /// </summary>
 /// <param name="logContext"></param>
 /// <param name="exception"></param>
 internal abstract void LogCommandHealthEvent(LogContext logContext, Exception exception);
コード例 #5
0
ファイル: MshLog.cs プロジェクト: 40a/PowerShell
        /// <summary>
        /// LogEngineHealthEvent: This is an API for logging engine health event while execution context
        /// is not available. In this case, caller of this API will directly construct LogContext 
        /// instance. 
        /// 
        /// This API is currently used only by runspace before engine start. 
        /// </summary>
        /// <param name="logContext">logContext to be </param>
        /// <param name="eventId">EventId for the event to be logged</param>
        /// <param name="exception">Exception associated with this event</param>
        /// <param name="additionalInfo">Additional information for this event</param>
        internal static void LogEngineHealthEvent(LogContext logContext,
                                                int eventId,
                                                Exception exception,
                                                Dictionary<String, String> additionalInfo
                                                )
        {
            if (logContext == null)
            {
                PSTraceSource.NewArgumentNullException("logContext");
                return;
            }

            if (exception == null)
            {
                PSTraceSource.NewArgumentNullException("exception");
                return;
            }

            // Here execution context doesn't exist, we will have to log this event regardless. 
            // Don't check NeedToLogEngineHealthEvent here. 
            foreach (LogProvider provider in GetLogProvider(logContext))
            {
                provider.LogEngineHealthEvent(logContext, eventId, exception, additionalInfo);
            }
        }
コード例 #6
0
ファイル: LogProvider.cs プロジェクト: 40a/PowerShell
 /// <summary>
 /// DummyLogProvider does nothing to Logging ProviderLifecycleEvent
 /// </summary>
 /// <param name="logContext"></param>
 /// <param name="providerName"></param>
 /// <param name="newState"></param>
 /// 
 internal override void LogProviderLifecycleEvent(LogContext logContext, string providerName, ProviderState newState)
 {
 }
コード例 #7
0
 /// <summary>
 /// DummyLogProvider does nothing to Logging SettingsEvent.
 /// </summary>
 /// <param name="logContext"></param>
 /// <param name="variableName"></param>
 /// <param name="value"></param>
 /// <param name="previousValue"></param>
 internal override void LogSettingsEvent(LogContext logContext, string variableName, string value, string previousValue)
 {
 }
コード例 #8
0
ファイル: EventLogLogProvider.cs プロジェクト: 40a/PowerShell
        /// <summary>
        /// Log settings event.
        /// </summary>
        /// <param name="logContext"></param>
        /// <param name="variableName"></param>
        /// <param name="value"></param>
        /// <param name="previousValue"></param>
        internal override void LogSettingsEvent(LogContext logContext, string variableName, string value, string previousValue)
        {
            int eventId = _settingsEventId;

            Hashtable mapArgs = new Hashtable();

            mapArgs["VariableName"] = variableName;
            mapArgs["NewValue"] = value;
            mapArgs["PreviousValue"] = previousValue;

            FillEventArgs(mapArgs, logContext);

            EventInstance entry = new EventInstance(eventId, SettingsCategoryId);

            entry.EntryType = EventLogEntryType.Information;

            string detail = GetEventDetail("SettingsContext", mapArgs);

            LogEvent(entry, variableName, value, previousValue, detail);
        }
コード例 #9
0
 /// <summary>
 /// Provider interface function for logging provider health event.
 /// </summary>
 /// <param name="logContext"></param>
 /// <param name="providerName"></param>
 /// <param name="exception"></param>
 internal override void LogProviderHealthEvent(LogContext logContext, string providerName, Exception exception)
 {
 }
コード例 #10
0
 /// <summary>
 /// DummyLogProvider does nothing to Logging ProviderLifecycleEvent.
 /// </summary>
 /// <param name="logContext"></param>
 /// <param name="providerName"></param>
 /// <param name="newState"></param>
 internal override void LogProviderLifecycleEvent(LogContext logContext, string providerName, ProviderState newState)
 {
 }
コード例 #11
0
 /// <summary>
 /// DummyLogProvider does nothing to Logging PipelineExecutionDetailEvent.
 /// </summary>
 /// <param name="logContext"></param>
 /// <param name="pipelineExecutionDetail"></param>
 internal override void LogPipelineExecutionDetailEvent(LogContext logContext, List <string> pipelineExecutionDetail)
 {
 }
コード例 #12
0
 /// <summary>
 /// Provider interface function for logging command health event.
 /// </summary>
 /// <param name="logContext"></param>
 /// <param name="exception"></param>
 internal override void LogCommandHealthEvent(LogContext logContext, Exception exception)
 {
 }
コード例 #13
0
 /// <summary>
 /// DummyLogProvider does nothing to Logging EngineLifecycleEvent.
 /// </summary>
 /// <param name="logContext"></param>
 /// <param name="newState"></param>
 /// <param name="previousState"></param>
 internal override void LogEngineLifecycleEvent(LogContext logContext, EngineState newState, EngineState previousState)
 {
 }
コード例 #14
0
ファイル: EventLogLogProvider.cs プロジェクト: 40a/PowerShell
        /// <summary>
        /// Log pipeline execution detail event.
        /// 
        /// This may end of logging more than one event if the detail string is too long to be fit in 64K. 
        /// </summary>
        /// <param name="logContext"></param>
        /// <param name="pipelineExecutionDetail"></param>
        internal override void LogPipelineExecutionDetailEvent(LogContext logContext, List<String> pipelineExecutionDetail)
        {
            List<String> details = GroupMessages(pipelineExecutionDetail);

            for (int i = 0; i < details.Count; i++)
            {
                LogPipelineExecutionDetailEvent(logContext, details[i], i + 1, details.Count);
            }
        }
コード例 #15
0
 /// <summary>
 /// Provider interface function for logging health event.
 /// </summary>
 /// <param name="logContext"></param>
 /// <param name="eventId"></param>
 /// <param name="exception"></param>
 /// <param name="additionalInfo"></param>
 internal abstract void LogEngineHealthEvent(LogContext logContext, int eventId, Exception exception, Dictionary <string, string> additionalInfo);
コード例 #16
0
ファイル: EventLogLogProvider.cs プロジェクト: 40a/PowerShell
        /// <summary>
        /// Provider interface function for logging provider health event
        /// </summary>
        /// <param name="logContext"></param>
        /// <param name="providerName"></param>
        /// <param name="exception"></param>
        /// 
        internal override void LogProviderHealthEvent(LogContext logContext, string providerName, Exception exception)
        {
            int eventId = _providerHealthEventId;

            Hashtable mapArgs = new Hashtable();

            mapArgs["ProviderName"] = providerName;

            IContainsErrorRecord icer = exception as IContainsErrorRecord;
            if (null != icer && null != icer.ErrorRecord)
            {
                mapArgs["ExceptionClass"] = exception.GetType().Name;
                mapArgs["ErrorCategory"] = icer.ErrorRecord.CategoryInfo.Category;
                mapArgs["ErrorId"] = icer.ErrorRecord.FullyQualifiedErrorId;

                if (icer.ErrorRecord.ErrorDetails != null
                    && !String.IsNullOrEmpty(icer.ErrorRecord.ErrorDetails.Message))
                {
                    mapArgs["ErrorMessage"] = icer.ErrorRecord.ErrorDetails.Message;
                }
                else
                {
                    mapArgs["ErrorMessage"] = exception.Message;
                }
            }
            else
            {
                mapArgs["ExceptionClass"] = exception.GetType().Name;
                mapArgs["ErrorCategory"] = "";
                mapArgs["ErrorId"] = "";
                mapArgs["ErrorMessage"] = exception.Message;
            }

            FillEventArgs(mapArgs, logContext);

            EventInstance entry = new EventInstance(eventId, ProviderHealthCategoryId);

            entry.EntryType = GetEventLogEntryType(logContext);

            string detail = GetEventDetail("ProviderHealthContext", mapArgs);

            LogEvent(entry, mapArgs["ErrorMessage"], detail);
        }
コード例 #17
0
 /// <summary>
 /// Provider interface function for logging engine lifecycle event.
 /// </summary>
 /// <param name="logContext"></param>
 /// <param name="newState"></param>
 /// <param name="previousState"></param>
 internal abstract void LogEngineLifecycleEvent(LogContext logContext, EngineState newState, EngineState previousState);
コード例 #18
0
ファイル: EventLogLogProvider.cs プロジェクト: 40a/PowerShell
        /// <summary>
        /// Log engine health event
        /// </summary>
        /// <param name="logContext"></param>
        /// <param name="eventId"></param>
        /// <param name="exception"></param>
        /// <param name="additionalInfo"></param>
        internal override void LogEngineHealthEvent(LogContext logContext, int eventId, Exception exception, Dictionary<String, String> additionalInfo)
        {
            Hashtable mapArgs = new Hashtable();

            IContainsErrorRecord icer = exception as IContainsErrorRecord;
            if (null != icer && null != icer.ErrorRecord)
            {
                mapArgs["ExceptionClass"] = exception.GetType().Name;
                mapArgs["ErrorCategory"] = icer.ErrorRecord.CategoryInfo.Category;
                mapArgs["ErrorId"] = icer.ErrorRecord.FullyQualifiedErrorId;

                if (icer.ErrorRecord.ErrorDetails != null)
                {
                    mapArgs["ErrorMessage"] = icer.ErrorRecord.ErrorDetails.Message;
                }
                else
                {
                    mapArgs["ErrorMessage"] = exception.Message;
                }
            }
            else
            {
                mapArgs["ExceptionClass"] = exception.GetType().Name;
                mapArgs["ErrorCategory"] = "";
                mapArgs["ErrorId"] = "";
                mapArgs["ErrorMessage"] = exception.Message;
            }

            FillEventArgs(mapArgs, logContext);

            FillEventArgs(mapArgs, additionalInfo);

            EventInstance entry = new EventInstance(eventId, EngineHealthCategoryId);

            entry.EntryType = GetEventLogEntryType(logContext);

            string detail = GetEventDetail("EngineHealthContext", mapArgs);

            LogEvent(entry, mapArgs["ErrorMessage"], detail);
        }
コード例 #19
0
 /// <summary>
 /// Provider interface function for logging command health event.
 /// </summary>
 /// <param name="logContext"></param>
 /// <param name="exception"></param>
 internal abstract void LogCommandHealthEvent(LogContext logContext, Exception exception);
コード例 #20
0
 /// <summary>
 /// Provider interface function for logging settings event.
 /// </summary>
 /// <param name="logContext"></param>
 /// <param name="variableName"></param>
 /// <param name="value"></param>
 /// <param name="previousValue"></param>
 internal abstract void LogSettingsEvent(LogContext logContext, string variableName, string value, string previousValue);
コード例 #21
0
 /// <summary>
 /// Provider interface function for logging pipeline execution detail.
 /// </summary>
 /// <param name="logContext"></param>
 /// <param name="pipelineExecutionDetail"></param>
 internal abstract void LogPipelineExecutionDetailEvent(LogContext logContext, List <string> pipelineExecutionDetail);
コード例 #22
0
ファイル: LogProvider.cs プロジェクト: 40a/PowerShell
 /// <summary>
 /// DummyLogProvider does nothing to Logging SettingsEvent
 /// </summary>
 /// <param name="logContext"></param>
 /// <param name="variableName"></param>
 /// <param name="value"></param>
 /// <param name="previousValue"></param>
 /// 
 internal override void LogSettingsEvent(LogContext logContext, string variableName, string value, string previousValue)
 {
 }
コード例 #23
0
 /// <summary>
 /// Provider interface function for logging provider health event.
 /// </summary>
 /// <param name="logContext"></param>
 /// <param name="providerName"></param>
 /// <param name="exception"></param>
 internal abstract void LogProviderHealthEvent(LogContext logContext, string providerName, Exception exception);
コード例 #24
0
ファイル: LogProvider.cs プロジェクト: 40a/PowerShell
 /// <summary>
 /// Provider interface function for logging engine lifecycle event
 /// </summary>
 /// <param name="logContext"></param>
 /// <param name="newState"></param>
 /// <param name="previousState"></param>
 /// 
 internal abstract void LogEngineLifecycleEvent(LogContext logContext, EngineState newState, EngineState previousState);
コード例 #25
0
 /// <summary>
 /// Provider interface function for logging provider lifecycle event.
 /// </summary>
 /// <param name="logContext"></param>
 /// <param name="providerName"></param>
 /// <param name="newState"></param>
 internal abstract void LogProviderLifecycleEvent(LogContext logContext, string providerName, ProviderState newState);
コード例 #26
0
ファイル: LogProvider.cs プロジェクト: 40a/PowerShell
 /// <summary>
 /// Provider interface function for logging pipeline execution detail.
 /// </summary>
 /// <param name="logContext"></param>
 /// <param name="pipelineExecutionDetail"></param>
 internal abstract void LogPipelineExecutionDetailEvent(LogContext logContext, List<String> pipelineExecutionDetail);
コード例 #27
0
ファイル: MshLog.cs プロジェクト: x1m0/PowerShell
        /// <summary>
        /// Generate LogContext structure based on executionContext and invocationInfo passed in.
        ///
        /// LogContext structure is used in log provider interface.
        /// </summary>
        /// <param name="executionContext"></param>
        /// <param name="invocationInfo"></param>
        /// <param name="severity"></param>
        /// <returns></returns>
        private static LogContext GetLogContext(ExecutionContext executionContext, InvocationInfo invocationInfo, Severity severity)
        {
            if (executionContext == null)
            {
                return(null);
            }

            LogContext logContext = new LogContext();

            string shellId = executionContext.ShellID;

            logContext.ExecutionContext = executionContext;
            logContext.ShellId          = shellId;
            logContext.Severity         = severity.ToString();

            if (executionContext.EngineHostInterface != null)
            {
                logContext.HostName    = executionContext.EngineHostInterface.Name;
                logContext.HostVersion = executionContext.EngineHostInterface.Version.ToString();
                logContext.HostId      = (string)executionContext.EngineHostInterface.InstanceId.ToString();
            }

            logContext.HostApplication = String.Join(" ", Environment.GetCommandLineArgs());

            if (executionContext.CurrentRunspace != null)
            {
                logContext.EngineVersion = executionContext.CurrentRunspace.Version.ToString();
                logContext.RunspaceId    = executionContext.CurrentRunspace.InstanceId.ToString();

                Pipeline currentPipeline = ((RunspaceBase)executionContext.CurrentRunspace).GetCurrentlyRunningPipeline();
                if (currentPipeline != null)
                {
                    logContext.PipelineId = currentPipeline.InstanceId.ToString(CultureInfo.CurrentCulture);
                }
            }

            logContext.SequenceNumber = NextSequenceNumber;

            try
            {
                if (executionContext.LogContextCache.User == null)
                {
                    logContext.User = Environment.UserDomainName + "\\" + Environment.UserName;
                    executionContext.LogContextCache.User = logContext.User;
                }
                else
                {
                    logContext.User = executionContext.LogContextCache.User;
                }
            }
            catch (InvalidOperationException)
            {
                logContext.User = Logging.UnknownUserName;
            }

            System.Management.Automation.Remoting.PSSenderInfo psSenderInfo =
                executionContext.SessionState.PSVariable.GetValue("PSSenderInfo") as System.Management.Automation.Remoting.PSSenderInfo;
            if (psSenderInfo != null)
            {
                logContext.ConnectedUser = psSenderInfo.UserInfo.Identity.Name;
            }

            logContext.Time = DateTime.Now.ToString(CultureInfo.CurrentCulture);

            if (invocationInfo == null)
            {
                return(logContext);
            }

            logContext.ScriptName  = invocationInfo.ScriptName;
            logContext.CommandLine = invocationInfo.Line;

            if (invocationInfo.MyCommand != null)
            {
                logContext.CommandName = invocationInfo.MyCommand.Name;
                logContext.CommandType = invocationInfo.MyCommand.CommandType.ToString();

                switch (invocationInfo.MyCommand.CommandType)
                {
                case CommandTypes.Application:
                    logContext.CommandPath = ((ApplicationInfo)invocationInfo.MyCommand).Path;
                    break;

                case CommandTypes.ExternalScript:
                    logContext.CommandPath = ((ExternalScriptInfo)invocationInfo.MyCommand).Path;
                    break;
                }
            }

            return(logContext);
        }
コード例 #28
0
ファイル: LogProvider.cs プロジェクト: 40a/PowerShell
 /// <summary>
 /// Provider interface function for logging provider lifecycle event
 /// </summary>
 /// <param name="logContext"></param>
 /// <param name="providerName"></param>
 /// <param name="newState"></param>
 /// 
 internal abstract void LogProviderLifecycleEvent(LogContext logContext, string providerName, ProviderState newState);
コード例 #29
0
ファイル: LogProvider.cs プロジェクト: 40a/PowerShell
 /// <summary>
 /// Provider interface function for logging settings event
 /// </summary>
 /// <param name="logContext"></param>
 /// <param name="variableName"></param>
 /// <param name="value"></param>
 /// <param name="previousValue"></param>
 /// 
 internal abstract void LogSettingsEvent(LogContext logContext, string variableName, string value, string previousValue);
コード例 #30
0
ファイル: EventLogLogProvider.cs プロジェクト: 40a/PowerShell
        /// <summary>
        /// Log engine lifecycle event
        /// </summary>
        /// <param name="logContext"></param>
        /// <param name="newState"></param>
        /// <param name="previousState"></param>
        internal override void LogEngineLifecycleEvent(LogContext logContext, EngineState newState, EngineState previousState)
        {
            int eventId = GetEngineLifecycleEventId(newState);

            if (eventId == _invalidEventId)
                return;

            Hashtable mapArgs = new Hashtable();

            mapArgs["NewEngineState"] = newState.ToString();
            mapArgs["PreviousEngineState"] = previousState.ToString();

            FillEventArgs(mapArgs, logContext);

            EventInstance entry = new EventInstance(eventId, EngineLifecycleCategoryId);

            entry.EntryType = EventLogEntryType.Information;

            string detail = GetEventDetail("EngineLifecycleContext", mapArgs);

            LogEvent(entry, newState, previousState, detail);
        }
コード例 #31
0
ファイル: LogProvider.cs プロジェクト: 40a/PowerShell
 /// <summary>
 /// DummyLogProvider does nothing to Logging EngineHealthEvent
 /// </summary>
 /// <param name="logContext"></param>
 /// <param name="eventId"></param>
 /// <param name="exception"></param>
 /// <param name="additionalInfo"></param>
 /// 
 internal override void LogEngineHealthEvent(LogContext logContext, int eventId, Exception exception, Dictionary<String, String> additionalInfo)
 {
 }
コード例 #32
0
ファイル: EventLogLogProvider.cs プロジェクト: 40a/PowerShell
        /// <summary>
        /// Log one pipeline execution detail event. Detail message is already chopped up so that it will 
        /// fit in 64K. 
        /// </summary>
        /// <param name="logContext"></param>
        /// <param name="pipelineExecutionDetail"></param>
        /// <param name="detailSequence"></param>
        /// <param name="detailTotal"></param>
        private void LogPipelineExecutionDetailEvent(LogContext logContext, String pipelineExecutionDetail, int detailSequence, int detailTotal)
        {
            int eventId = _pipelineExecutionDetailEventId;

            Hashtable mapArgs = new Hashtable();

            mapArgs["PipelineExecutionDetail"] = pipelineExecutionDetail;
            mapArgs["DetailSequence"] = detailSequence;
            mapArgs["DetailTotal"] = detailTotal;

            FillEventArgs(mapArgs, logContext);

            EventInstance entry = new EventInstance(eventId, PipelineExecutionDetailCategoryId);

            entry.EntryType = EventLogEntryType.Information;

            string pipelineInfo = GetEventDetail("PipelineExecutionDetailContext", mapArgs);

            LogEvent(entry, logContext.CommandLine, pipelineInfo, pipelineExecutionDetail);
        }
コード例 #33
0
ファイル: LogProvider.cs プロジェクト: 40a/PowerShell
 /// <summary>
 /// DummyLogProvider does nothing to Logging EngineLifecycleEvent
 /// </summary>
 /// <param name="logContext"></param>
 /// <param name="newState"></param>
 /// <param name="previousState"></param>
 /// 
 internal override void LogEngineLifecycleEvent(LogContext logContext, EngineState newState, EngineState previousState)
 {
 }
コード例 #34
0
ファイル: EventLogLogProvider.cs プロジェクト: 40a/PowerShell
        /// <summary>
        /// Log provider lifecycle event.
        /// </summary>
        /// <param name="logContext"></param>
        /// <param name="providerName"></param>
        /// <param name="newState"></param>
        internal override void LogProviderLifecycleEvent(LogContext logContext, string providerName, ProviderState newState)
        {
            int eventId = GetProviderLifecycleEventId(newState);

            if (eventId == _invalidEventId)
                return;

            Hashtable mapArgs = new Hashtable();

            mapArgs["ProviderName"] = providerName;
            mapArgs["NewProviderState"] = newState.ToString();

            FillEventArgs(mapArgs, logContext);

            EventInstance entry = new EventInstance(eventId, ProviderLifecycleCategoryId);

            entry.EntryType = EventLogEntryType.Information;

            string detail = GetEventDetail("ProviderLifecycleContext", mapArgs);

            LogEvent(entry, providerName, newState, detail);
        }
コード例 #35
0
ファイル: LogProvider.cs プロジェクト: 40a/PowerShell
 /// <summary>
 /// Provider interface function for logging command health event
 /// </summary>
 /// <param name="logContext"></param>
 /// <param name="exception"></param>
 /// 
 internal override void LogCommandHealthEvent(LogContext logContext, Exception exception)
 {
 }
コード例 #36
0
ファイル: EventLogLogProvider.cs プロジェクト: 40a/PowerShell
 /// <summary>
 /// Fill event arguments with logContext info.
 /// 
 /// In EventLog Api, arguments are passed in as an array of objects. 
 /// </summary>
 /// <param name="mapArgs">An ArrayList to contain the event arguments</param>
 /// <param name="logContext">The log context containing the info to fill in</param>
 private static void FillEventArgs(Hashtable mapArgs, LogContext logContext)
 {
     mapArgs["Severity"] = logContext.Severity;
     mapArgs["SequenceNumber"] = logContext.SequenceNumber;
     mapArgs["HostName"] = logContext.HostName;
     mapArgs["HostVersion"] = logContext.HostVersion;
     mapArgs["HostId"] = logContext.HostId;
     mapArgs["HostApplication"] = logContext.HostApplication;
     mapArgs["EngineVersion"] = logContext.EngineVersion;
     mapArgs["RunspaceId"] = logContext.RunspaceId;
     mapArgs["PipelineId"] = logContext.PipelineId;
     mapArgs["CommandName"] = logContext.CommandName;
     mapArgs["CommandType"] = logContext.CommandType;
     mapArgs["ScriptName"] = logContext.ScriptName;
     mapArgs["CommandPath"] = logContext.CommandPath;
     mapArgs["CommandLine"] = logContext.CommandLine;
     mapArgs["User"] = logContext.User;
     mapArgs["Time"] = logContext.Time;
 }
コード例 #37
0
ファイル: LogProvider.cs プロジェクト: 40a/PowerShell
 /// <summary>
 /// DummyLogProvider does nothing to Logging PipelineExecutionDetailEvent.
 /// </summary>
 /// <param name="logContext"></param>
 /// <param name="pipelineExecutionDetail"></param>
 internal override void LogPipelineExecutionDetailEvent(LogContext logContext, List<String> pipelineExecutionDetail)
 {
 }
コード例 #38
0
ファイル: MshLog.cs プロジェクト: 40a/PowerShell
        /// <summary>
        /// Get Log Provider based on Log Context 
        /// </summary>
        /// 
        /// <param name="logContext"></param>
        /// <returns></returns>
        private static IEnumerable<LogProvider> GetLogProvider(LogContext logContext)
        {
            System.Diagnostics.Debug.Assert(logContext != null);
            System.Diagnostics.Debug.Assert(!String.IsNullOrEmpty(logContext.ShellId));

            return GetLogProvider(logContext.ShellId);
        }
コード例 #39
0
ファイル: LogProvider.cs プロジェクト: 40a/PowerShell
 /// <summary>
 /// Provider interface function for logging provider health event
 /// </summary>
 /// <param name="logContext"></param>
 /// <param name="providerName"></param>
 /// <param name="exception"></param>
 /// 
 internal override void LogProviderHealthEvent(LogContext logContext, string providerName, Exception exception)
 {
 }
コード例 #40
0
ファイル: MshLog.cs プロジェクト: 40a/PowerShell
        /// <summary>
        /// Generate LogContext structure based on executionContext and invocationInfo passed in.
        /// 
        /// LogContext structure is used in log provider interface. 
        /// </summary>
        /// <param name="executionContext"></param>
        /// <param name="invocationInfo"></param>
        /// <param name="severity"></param>
        /// <returns></returns>
        private static LogContext GetLogContext(ExecutionContext executionContext, InvocationInfo invocationInfo, Severity severity)
        {
            if (executionContext == null)
                return null;

            LogContext logContext = new LogContext();

            string shellId = executionContext.ShellID;

            logContext.ExecutionContext = executionContext;
            logContext.ShellId = shellId;
            logContext.Severity = severity.ToString();

            if (executionContext.EngineHostInterface != null)
            {
                logContext.HostName = executionContext.EngineHostInterface.Name;
                logContext.HostVersion = executionContext.EngineHostInterface.Version.ToString();
                logContext.HostId = (string)executionContext.EngineHostInterface.InstanceId.ToString();
            }

            logContext.HostApplication = String.Join(" ", Environment.GetCommandLineArgs());

            if (executionContext.CurrentRunspace != null)
            {
                logContext.EngineVersion = executionContext.CurrentRunspace.Version.ToString();
                logContext.RunspaceId = executionContext.CurrentRunspace.InstanceId.ToString();

                Pipeline currentPipeline = ((RunspaceBase)executionContext.CurrentRunspace).GetCurrentlyRunningPipeline();
                if (currentPipeline != null)
                {
                    logContext.PipelineId = currentPipeline.InstanceId.ToString(CultureInfo.CurrentCulture);
                }
            }

            logContext.SequenceNumber = NextSequenceNumber;

            try
            {
                if (executionContext.LogContextCache.User == null)
                {
                    logContext.User = Environment.UserDomainName + "\\" + Environment.UserName;
                    executionContext.LogContextCache.User = logContext.User;
                }
                else
                {
                    logContext.User = executionContext.LogContextCache.User;
                }
            }
            catch (InvalidOperationException)
            {
                logContext.User = Logging.UnknownUserName;
            }

            System.Management.Automation.Remoting.PSSenderInfo psSenderInfo =
                    executionContext.SessionState.PSVariable.GetValue("PSSenderInfo") as System.Management.Automation.Remoting.PSSenderInfo;
            if (psSenderInfo != null)
            {
                logContext.ConnectedUser = psSenderInfo.UserInfo.Identity.Name;
            }

            logContext.Time = DateTime.Now.ToString(CultureInfo.CurrentCulture);

            if (invocationInfo == null)
                return logContext;

            logContext.ScriptName = invocationInfo.ScriptName;
            logContext.CommandLine = invocationInfo.Line;

            if (invocationInfo.MyCommand != null)
            {
                logContext.CommandName = invocationInfo.MyCommand.Name;
                logContext.CommandType = invocationInfo.MyCommand.CommandType.ToString();

                switch (invocationInfo.MyCommand.CommandType)
                {
                    case CommandTypes.Application:
                        logContext.CommandPath = ((ApplicationInfo)invocationInfo.MyCommand).Path;
                        break;
                    case CommandTypes.ExternalScript:
                        logContext.CommandPath = ((ExternalScriptInfo)invocationInfo.MyCommand).Path;
                        break;
                }
            }

            return logContext;
        }
コード例 #41
0
ファイル: LogProvider.cs プロジェクト: rsumner31/powershell
 /// <summary>
 /// DummyLogProvider does nothing to Logging EngineHealthEvent
 /// </summary>
 /// <param name="logContext"></param>
 /// <param name="eventId"></param>
 /// <param name="exception"></param>
 /// <param name="additionalInfo"></param>
 ///
 internal override void LogEngineHealthEvent(LogContext logContext, int eventId, Exception exception, Dictionary <String, String> additionalInfo)
 {
 }