Пример #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;
        }
Пример #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.");
     }
 }