当前位置: 首页>>代码示例>>C#>>正文


C# ILogWriter.GetType方法代码示例

本文整理汇总了C#中ILogWriter.GetType方法的典型用法代码示例。如果您正苦于以下问题:C# ILogWriter.GetType方法的具体用法?C# ILogWriter.GetType怎么用?C# ILogWriter.GetType使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ILogWriter的用法示例。


在下文中一共展示了ILogWriter.GetType方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: AddLogWriter

        /// <summary>
        /// Adds a log writer and binds to a specific log message type
        /// </summary>
        /// <param name="logMessageType">Type of log message</param>
        /// <param name="logWriter">Log writer to add</param>
        public void AddLogWriter(NiawaLogType logMessageType, ILogWriter logWriter)
        {
            //Ensure that more than one instance of a ILogWriter implementation (of a specific type) is not added.
            if(_logWriters.ContainsKey(logWriter.GetType().ToString()))
                if (_logWriters[logWriter.GetType().ToString()].LogWriterID != logWriter.LogWriterID)
                    throw new Exception("Cannot add two instances of the same ILogWriter type [" + logWriter.GetType().ToString() + "].  Add a different type of ILogWriter, or add an existing instance of this ILogWriter type.");

             //Check for duplicate entry attempts into the LogMessageTypeLogWriters collection
            if (_logMessageTypeLogWriters.ContainsKey(logMessageType))
                if (_logMessageTypeLogWriters[logMessageType].Contains(logWriter))
                    throw new Exception("Cannot add the same ILogWriter [" + logWriter.GetType().ToString() + "] for LogMessageType [" + Enum.GetName(logMessageType.GetType(), logMessageType) + "] more than once.");

            //add log writer to list
            if (!(_logWriters.ContainsKey(logWriter.GetType().ToString())))
                _logWriters.Add(logWriter.GetType().ToString(), logWriter);

            //add log writer to map
            List<ILogWriter> mapLogWriters = null;

            //check if log message type already in map
            if (_logMessageTypeLogWriters.ContainsKey(logMessageType))
                mapLogWriters = _logMessageTypeLogWriters[logMessageType];
            else
            {
                //create new entry of log writers for log message type and add to map
                mapLogWriters = new List<ILogWriter>();
                _logMessageTypeLogWriters.Add(logMessageType, mapLogWriters);
            }

            //add log writer to list of log writers mapped to log message type
            mapLogWriters.Add(logWriter);
        }
开发者ID:nickw4827,项目名称:NiawaAHN_Step2_Logging,代码行数:37,代码来源:BufferedLogger.cs


注:本文中的ILogWriter.GetType方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。