Ejemplo n.º 1
0
        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="element">LogListenerElement对象</param>
        /// <remarks>
        /// <code source="..\Framework\TestProjects\DeluxeWorks.Library.Test\Logging\ListenerTest.cs"
        /// lang="cs" region="FlatFileTraceListener Test" tittle="创建Listener对象"></code>
        /// </remarks>
        public FlatFileTraceListener(LogListenerElement element)
        {
            this.Name = element.Name;

            string filenameFormat = string.Empty;

            if (element.ExtendedAttributes.TryGetValue("filenameFormat", out filenameFormat) == false)
            {
                filenameFormat = element.Name + ".log";
            }

            string     filename = RootFileNameAndEnsureTargetFolderExists(filenameFormat);
            FileStream fs       = new FileStream(filename, FileMode.Append, FileAccess.Write, FileShare.ReadWrite);
            TextWriterTraceListener textlistener = new TextWriterTraceListener(fs, this.Name);

            this.SlaveListener = textlistener;

            if (element.ExtendedAttributes.TryGetValue("header", out this.header) == false)
            {
                this.header = string.Empty;
            }
            if (element.ExtendedAttributes.TryGetValue("footer", out this.footer) == false)
            {
                this.footer = string.Empty;
            }

            this.formatterName = element.LogFormatterName;

            //string filename;
            //element.ExtendedAttributes.TryGetValue("fileName", out filename);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="element">LogListenerElement对象</param>
        /// <remarks>
        /// 根据配置信息创建FormattedEventLogTraceListener对象
        /// <code source="..\Framework\TestProjects\DeluxeWorks.Library.Test\\Logging\ListenerTest.cs"
        /// lang="cs" region="EventLogTraceListener Test" tittle="创建Listener对象"></code>
        /// </remarks>
        public FormattedEventLogTraceListener(LogListenerElement element)
        {
            this.formatterName = element.LogFormatterName;
            this.Name          = element.Name;

            if (element.ExtendedAttributes.TryGetValue("logName", out this.logName) == false)
            {
                this.logName = FormattedEventLogTraceListener.DefaultLogName;
            }

            if (element.ExtendedAttributes.TryGetValue("source", out this.source) == false)
            {
                this.source = string.IsNullOrEmpty(this.logName) ? FormattedEventLogTraceListener.DefaultSource : this.logName;
            }

            this.SlaveListener = new EventLogTraceListener();
        }
Ejemplo n.º 3
0
        ///Add by JerryShi for create log by text writer

        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="element">LogListenerElement对象</param>
        /// <remarks>
        /// 根据配置信息创建FormattedEventLogTraceListener对象
        /// <code source="..\Framework\TestProjects\DeluxeWorks.Library.Test\\Logging\ListenerTest.cs"
        /// lang="cs" region="EventLogTraceListener Test" tittle="创建Listener对象"></code>
        /// </remarks>
        public FormattedTextWriterTraceListener(LogListenerElement element)
        {
            this.formatterName = element.LogFormatterName;
            this.Name          = element.Name;

            if (element.ExtendedAttributes.TryGetValue("logFileName", out this.logFileName) == false)
            {
                this.logFileName = FormattedTextWriterTraceListener.DefaultLogFileName;
            }

            this.logFileName = RootFileNameAndEnsureTargetFolderExists(this.logFileName);

            FileStream fs = new FileStream(this.logFileName, FileMode.Append, FileAccess.Write, FileShare.ReadWrite);
            TextWriterTraceListener textlistener = new TextWriterTraceListener(fs, this.Name);

            this.SlaveListener = textlistener;
            //if (element.ExtendedAttributes.TryGetValue("source", out this.source) == false)
            //    this.source = string.IsNullOrEmpty(this.logName) ? FormattedEventLogTraceListener.DefaultSource : this.logName;

            //this.SlaveListener = new TextWriterTraceListener();
        }
Ejemplo n.º 4
0
 private static FormattedTraceListenerBase GetListenerFromConfig(LogListenerElement element)
 {
     return((FormattedTraceListenerBase)TypeCreator.CreateInstance(element.Type, element));
     //return ObjectBuilder.GetInstance<TraceListener>(element.TypeName);
 }