Beispiel #1
0
        internal static EventLogger Create(String serviceName, Int32 bufferSize)
        {
            EventLogger instance = new EventLogger();

            // create storages
            List<ILoggerStorage> storages = new List<ILoggerStorage>();
            storages.Add(new LoggerFileStorage(serviceName));

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

            return instance;
        }
Beispiel #2
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;
        }