Пример #1
0
        /// <summary>
        ///   Initializes a new instance of the <see cref="NLogFactory" /> class.
        /// </summary>
        public NLogFactory()
            : this(defaultConfigFileName)
        {
            /*
             *  The following creates an easy way to get at the private static LogicalThreadDictionary of NLog's MappedDiagnosticsLogicalContext.
             *  It does some IL emitting, so it's not the most maintainable, but it's a once only cost at applicaiton startup.
             *  There are probably other ways to achieve the same thing, but none as performant.
             */
            var type1 = typeof(MappedDiagnosticsContext);
            var getLogicalThreadDictionary1 = type1.GetMethod("GetLogicalThreadDictionary", BindingFlags.Static | BindingFlags.NonPublic);

            var method1 = new DynamicMethod("GetMappedDiagnosticsLogicalContext", typeof(IDictionary <string, object>), null, typeof(MappedDiagnosticsLogicalContext), true);
            var ilGen1  = method1.GetILGenerator();
            ilGen1.Emit(OpCodes.Call, getLogicalThreadDictionary1);
            ilGen1.Emit(OpCodes.Ret);

            logicalThreadDictionary = (MappedDiagnosticsLogicalContextDelegate)method1.CreateDelegate(typeof(MappedDiagnosticsLogicalContextDelegate));
        }
 public NLogLogger(Logger logger, NLogFactory factory, MappedDiagnosticsLogicalContextDelegate mappedDiagnosticsLogicalContextDelegate)
     : this(logger, factory)
 {
     this.mappedDiagnosticsLogicalContextDelegate = mappedDiagnosticsLogicalContextDelegate;
 }