Esempio n. 1
0
        /// <summary>
        /// Creates and initializes an instance of the trace logger.
        /// </summary>
        /// <remarks>
        /// <para>
        /// After calling this method it is possible to start logging.
        /// </para>
        /// <para>
        /// Several storages can be used. In addition to a standard storage
        /// LoggerFileStorage other storages can be configured in settings.
        /// </para>
        /// </remarks>
        /// <param name="serviceName">Service name</param>
        /// <param name="bufferSize">Size of the buffer of log records (number
        /// of records).</param>
        /// <param name="isDebugMode">Indicates whether the services is ran in
        /// debug mode or as an NT service.</param>
        /// <param name="settings">Trace logger settings</param>
        /// <param name="eventLogger">Event logger for usage within storages.
        /// </param>
        /// <returns>Initialized trace logger instance.</returns>
        internal static TraceLogger Create(
            string serviceName,
            int bufferSize,
            bool isDebugMode,
            TraceLoggerSettings settings,
            EventLogger eventLogger)
        {
            TraceLogger instance = new TraceLogger();

            List<ILoggerStorage> storages = new List<ILoggerStorage>();

            // add standard storage
            storages.Add(new LoggerFileStorage(string.Format("{0}.Trace", serviceName)));

            // add configured storages
            foreach (TraceLoggerStorageSettings traceLoggerSettings in settings.Storages)
            {
                // create and initialize storage
                TraceLoggerStorage storage = TypesProvider.CreateTraceLoggerStorage(
                    traceLoggerSettings.TypeClass, traceLoggerSettings.TypeAssembly);
                storage.Event = eventLogger;

                // create adapter and start storage
                TraceLoggerStorageAdapter storageWrapper = new TraceLoggerStorageAdapter(storage);
                storageWrapper.Start(traceLoggerSettings.Name, isDebugMode, traceLoggerSettings.Settings);

                storages.Add(storageWrapper);
            }

            instance.storages = storages.ToArray();
            instance.loggerImpl = LoggerImplementation.Start(instance.storages, bufferSize);

            return instance;
        }
Esempio n. 2
0
 // TODO: Is it necessary to initialize trace logger separately from
 // the Create() method?
 internal void CreateTraceLogger(TraceLoggerSettings settings)
 {
     try
     {
         this.Trace = TraceLogger.Create(serviceName, settings.BufferSize,
             this.isDebugMode, settings, this.Event);
     }
     catch (UnauthorizedAccessException)
     {
         throw new ApplicationException(
             "Cannot create trace log. Try to run the program with administrator privileges.");
     }
 }
Esempio n. 3
0
        private static XElement SerializeTraceLoggerSettings(TraceLoggerSettings traceLogger)
        {
            XElement xTraceLogger = new XElement("trace-logger");
            if (traceLogger == null)
            {
                return xTraceLogger;
            }

            xTraceLogger.SetAttributeValue("buffer-size", traceLogger.BufferSize);
            foreach (var storage in traceLogger.Storages)
            {
                XElement xStorage = new XElement("storage");
                xStorage.SetAttributeValue("name", storage.Name);
                xStorage.SetAttributeValue("type",
                    SerializeType(storage.TypeClass, storage.TypeAssembly));

                XElement xSettings = SerializeSettings(storage.Settings);
                xStorage.Add(xSettings);
                xTraceLogger.Add(xStorage);
            }

            return xTraceLogger;
        }
Esempio n. 4
0
 public ServiceSettings()
 {
     Settings = new Settings();
     InstallerSettings = new InstallerSettings();
     TraceLoggerSettings = new TraceLoggerSettings();
 }
Esempio n. 5
0
        private static TraceLoggerSettings DeserializeTraceLoggerSettings(XElement xTraceLogger)
        {
            TraceLoggerSettings result = new TraceLoggerSettings();

            if (xTraceLogger == null)
            {
                return result;
            }

            // @buffer-size
            XAttribute xTraceBufferSize = xTraceLogger.Attribute(XName.Get("buffer-size"));
            if (xTraceBufferSize != null)
            {
                result.BufferSize = Convert.ToInt32(xTraceBufferSize.Value);
            }

            // storage
            foreach (XElement xStorage in xTraceLogger.XPathSelectElements("./storage"))
            {
                TraceLoggerStorageSettings traceLogger = new TraceLoggerStorageSettings();

                // @name
                traceLogger.Name = xStorage.Attribute(XName.Get("name")).Value;

                // @type
                string className;
                string assemblyName;
                DeserializeType(xStorage, out className, out assemblyName);
                traceLogger.TypeClass = className;
                traceLogger.TypeAssembly = assemblyName;

                // settings
                XElement xSettings = xStorage.XPathSelectElement("./settings");
                traceLogger.Settings = DeserializeSettings(xSettings);

                result.Storages.Add(traceLogger);
            }

            return result;
        }