コード例 #1
0
ファイル: logger.cs プロジェクト: BGCX261/ziggis-svn-to-git
 public void leaveFunc()
 {
     if (internalLog.IsDebugEnabled)
     {
         internalLog.Debug("[exit]");
     }
     NDC.Pop();
 }
コード例 #2
0
            public void Dispose()
            {
                string s = NDC.Pop();

                if (_logger.Logger.IsEnabledFor(Level.Info))
                {
                    _logger.InfoFormat("EndScope={0}", s);
                }
            }
コード例 #3
0
        /// <summary>
        /// The entry point for the interop test coordinator. This client accepts the following command line arguments:
        /// </summary>
        ///
        /// <p/><table>
        /// <tr><td> -b         <td> The broker URL.       <td> Optional.
        /// <tr><td> -h         <td> The virtual host.     <td> Optional.
        /// <tr><td> -n         <td> The test client name. <td> Optional.
        /// <tr><td> name=value <td> Trailing argument define name/value pairs. Added to system properties. <td> Optional.
        /// </table>
        ///
        /// <param name="args"> The command line arguments. </param>
        public static void Main(string[] args)
        {
            // Extract the command line options (Not exactly Posix but it will do for now...).
            string brokerUrl   = DEFAULT_BROKER_URL;
            string virtualHost = DEFAULT_VIRTUAL_HOST;
            string clientName  = DEFAULT_CLIENT_NAME;

            foreach (string nextArg in args)
            {
                if (nextArg.StartsWith("-b"))
                {
                    brokerUrl = nextArg.Substring(2);
                }
                else if (nextArg.StartsWith("-h"))
                {
                    virtualHost = nextArg.Substring(2);
                }
                else if (nextArg.StartsWith("-n"))
                {
                    clientName = nextArg.Substring(2);
                }
            }

            NDC.Push(clientName);

            // Create a test client and start it running.
            TestClient client = new TestClient(brokerUrl, virtualHost, clientName);

            try
            {
                client.Start();
            }
            catch (Exception e)
            {
                log.Error("The test client was unable to start.", e);
                System.Environment.Exit(1);
            }

            // Wait for a signal on the termination monitor before quitting.
            lock (terminationMonitor)
            {
                Monitor.Wait(terminationMonitor);
            }

            NDC.Pop();
        }
コード例 #4
0
 public Log(string ndc = null)
 {
     typeName = typeof(T).TypeName();
     log      = LogManager.GetLogger(typeName);
     if (!string.IsNullOrEmpty(ndc))
     {
         this.ndc = ndc;
     }
     else
     {
         this.ndc = HttpContext.Current.Items["LogContextName"]?.ToString();
     }
     if (string.IsNullOrEmpty(this.ndc) && NDC.Depth == 1)
     {
         this.ndc = NDC.Pop();
         init();
     }
 }
コード例 #5
0
 private void ExceptionHandler(Delegate method, params object[] parameters)
 {
     NDC.Push(_clientID);
     try
     {
         if (method is WaitOrTimerCallback)
         {
             ((WaitOrTimerCallback)method)(parameters[0], (bool)parameters[1]);
         }
         else if (method is WaitCallback)
         {
             ((WaitCallback)method)(parameters[0]);
         }
         else if (method is AsyncCallback)
         {
             ((AsyncCallback)method)((IAsyncResult)parameters[0]);
         }
         else
         {
             method.DynamicInvoke(parameters);
         }
     }
     catch (TargetInvocationException targetEx)
     {
         ExceptionHandlerInfo(targetEx.InnerException ?? targetEx);
         SessionEnd();
     }
     catch (Exception ex)
     {
         ExceptionHandlerInfo(ex);
         SessionEnd();
     }
     finally
     {
         NDC.Pop();
     }
 }
コード例 #6
0
        public void NDCTest2()
        {
            List <Exception> exceptions = new List <Exception>();
            ManualResetEvent mre        = new ManualResetEvent(false);
            int counter   = 500;
            int remaining = counter;

            for (int i = 0; i < counter; ++i)
            {
                ThreadPool.QueueUserWorkItem(
                    s =>
                {
                    try
                    {
                        NDC.Clear();
                        Assert.AreEqual(string.Empty, NDC.TopMessage);
                        Assert.AreEqual(string.Empty, NDC.Pop());
                        AssertContents(NDC.GetAllMessages());
                        using (NDC.Push("foo"))
                        {
                            Assert.AreEqual("foo", NDC.TopMessage);
                            AssertContents(NDC.GetAllMessages(), "foo");
                            using (NDC.Push("bar"))
                            {
                                AssertContents(NDC.GetAllMessages(), "bar", "foo");
                                Assert.AreEqual("bar", NDC.TopMessage);
                                NDC.Push("baz");
                                AssertContents(NDC.GetAllMessages(), "baz", "bar", "foo");
                                Assert.AreEqual("baz", NDC.TopMessage);
                                Assert.AreEqual("baz", NDC.Pop());

                                AssertContents(NDC.GetAllMessages(), "bar", "foo");
                                Assert.AreEqual("bar", NDC.TopMessage);
                            }

                            AssertContents(NDC.GetAllMessages(), "foo");
                            Assert.AreEqual("foo", NDC.TopMessage);
                        }

                        AssertContents(NDC.GetAllMessages());
                        Assert.AreEqual(string.Empty, NDC.Pop());
                    }
                    catch (Exception ex)
                    {
                        lock (exceptions)
                        {
                            exceptions.Add(ex);
                        }
                    }
                    finally
                    {
                        if (Interlocked.Decrement(ref remaining) == 0)
                        {
                            mre.Set();
                        }
                    }
                });
            }

            mre.WaitOne();
            Assert.AreEqual(0, exceptions.Count);
        }
コード例 #7
0
 private static void PostProcessLogEntry()
 {
     NDC.Pop();
 }
コード例 #8
0
        /// <summary>
        /// It's the handler of the asynchronous reading.
        /// </summary>
        /// <param name="asyncResult">
        /// It is the result of the asynchronous reading.
        /// </param>
        private void AsyncAcceptRequestHandler(IAsyncResult asyncResult)
        {
            if (asyncResult.AsyncState == _socket)
            {
                Socket socket = null;
                lock (this) {
                    if (asyncResult.AsyncState == _socket)
                    {
                        if (!_listening)
                        {
                            // Someone called Close over socket. EndAccept and return.
                            try {
                                _socket.EndAccept(asyncResult);
                            } catch {
                            }
                            Monitor.Pulse(this);
                            return;
                        }

                        try {
                            // Accept connection.
                            socket = _socket.EndAccept(asyncResult);
                        } catch (Exception e) {
                            OnError(e);
                            return;
                        }

                        try {
                            // Start an asynchronous accept operation.
                            _socket.BeginAccept(new AsyncCallback(AsyncAcceptRequestHandler), _socket);
                        } catch (Exception e) {
                            Stop();
                            OnError(e);
                        }
                    }
                }

                if (socket == null)
                {
                    return;
                }

                IChannel channel = null;
                try {
                    if (socket.RemoteEndPoint == null)
                    {
                        NDC.Push(string.Format("{0}<-?", GetNDCName()));
                    }
                    else
                    {
                        NDC.Push(string.Format("{0}<-{1}", GetNDCName(), socket.RemoteEndPoint.ToString()));
                    }

                    if ((_channelPool != null) &&
                        OnConnectionRequest(socket.RemoteEndPoint))
                    {
                        channel = _channelPool.Remove();
                        if (channel == null)
                        {
                            if (Logger.IsInfoEnabled)
                            {
                                Logger.Info(string.Format(
                                                "Connection request from {0}, not accepted because channel pool is empty.",
                                                socket.RemoteEndPoint.ToString()));
                            }

                            // Can't get a channel for the new connection, close it.
                            socket.Shutdown(SocketShutdown.Both);
                            socket = null;
                        }
                        else
                        {
                            channel.BeginBind(socket);
                        }
                    }
                    else
                    {
                        if (Logger.IsInfoEnabled)
                        {
                            if (_channelPool == null)
                            {
                                Logger.Info(string.Format(
                                                "Connection request from {0}, not accepted because channel pool is null.",
                                                socket.RemoteEndPoint.ToString()));
                            }
                            else
                            {
                                Logger.Info(string.Format(
                                                "Connection request from {0}, not accepted.",
                                                socket.RemoteEndPoint.ToString()));
                            }
                        }

                        // Connection not accepted, close it.
                        socket.Shutdown(SocketShutdown.Both);
                    }
                } catch (Exception e) {
                    try {
                        OnError(e);

                        socket.Shutdown(SocketShutdown.Both);

                        // Return channel to the pool.
                        if (channel != null)
                        {
                            _channelPool.Add(channel);
                            channel = null;

                            if (Logger.IsInfoEnabled)
                            {
                                Logger.Info(string.Format(
                                                "Channel returned to pool, {0} channel/s remaining in channel pool.",
                                                _channelPool.Length));
                            }
                        }
                    } catch {
                    }
                } finally {
                    NDC.Pop();
                }

                if (channel != null)
                {
                    try {
                        NDC.Push(string.Format("{0}<-{1}", GetNDCName(), socket.RemoteEndPoint.ToString()));

                        // It is necessary first to raise the event, and soon the EndBind. Doing this
                        // the components that receive the event can initialize before the channel
                        // begins to receive.
                        OnConnected(channel);
                        channel.EndBind();
                    } catch (Exception e) {
                        try {
                            channel.Close();

                            OnError(e);

                            // Return channel to the pool.
                            if (channel != null)
                            {
                                _channelPool.Add(channel);
                                channel = null;

                                if (Logger.IsInfoEnabled)
                                {
                                    Logger.Info(string.Format(
                                                    "Channel returned to pool, {0} channel/s remaining in channel pool.",
                                                    _channelPool.Length));
                                }
                            }
                        } catch {
                        }
                    } finally {
                        NDC.Pop();
                    }
                }
            }
        }