Exemplo n.º 1
0
        /// <summary>
        /// Builds a <see cref="ILoggerFactoryAdapter"/> instance from the given <see cref="LogSetting"/>
        /// using <see cref="Activator"/>.
        /// </summary>
        /// <param name="setting"></param>
        /// <returns>the <see cref="ILoggerFactoryAdapter"/> instance. Is never <c>null</c></returns>
        private static ILoggerFactoryAdapter BuildLoggerFactoryAdapterFromLogSettings(LogSetting setting)
        {
            ArgUtils.AssertNotNull("setting", setting);
            // already ensured by LogSetting
            //            AssertArgIsAssignable<ILoggerFactoryAdapter>("setting.FactoryAdapterType", setting.FactoryAdapterType
            //                                , "Specified FactoryAdapter does not implement {0}.  Check implementation of class {1}"
            //                                , typeof(ILoggerFactoryAdapter).FullName
            //                                , setting.FactoryAdapterType.AssemblyQualifiedName);

            ILoggerFactoryAdapter adapter = null;

            ArgUtils.Guard(delegate
            {
                if (setting.Properties != null &&
                    setting.Properties.Count > 0)
                {
                    object[] args = { setting.Properties };

                    adapter = (ILoggerFactoryAdapter)Activator.CreateInstance(setting.FactoryAdapterType, args);
                }
                else
                {
                    adapter = (ILoggerFactoryAdapter)Activator.CreateInstance(setting.FactoryAdapterType);
                }
            }
                           , "Unable to create instance of type {0}. Possible explanation is lack of zero arg and single arg NameValueCollection constructors"
                           , setting.FactoryAdapterType.FullName
                           );

            // make sure
            ArgUtils.AssertNotNull("adapter", adapter, "Activator.CreateInstance() returned <null>");
            return(adapter);
        }
Exemplo n.º 2
0
 /// <summary>
 /// Create a new logger instance.
 /// </summary>
 public CapturingLogger(CapturingLoggerFactoryAdapter owner, string logName)
     : base(logName, LogLevel.All, true, true, true, null)
 {
     ArgUtils.AssertNotNull("owner", owner);
     Owner = owner;
 }
Exemplo n.º 3
0
 /// <summary>
 /// Creates this target using a custom layout.
 /// </summary>
 public CommonLoggingTarget(string layout)
 {
     ArgUtils.AssertNotNull("layout", layout);
     this.Layout = layout;
 }