public TraceMessage(TraceLevels type, DateTime dateTime, string message, string threadId)
 {
     Type = type;
     DateTime = dateTime;
     Message = message;
     ThreadId = threadId;
 }
Beispiel #2
0
        public static void Trace(TraceLevels type, string message, params object[] args)
        {
            lock (_syncRoot)
            {
                if (TraceReceived != null)
                {
                    if (args.Length > 0)
                    {
                        message = string.Format(message, args);
                    }

                    TraceMessage traceMessage =
                        new TraceMessage(type, DateTime.UtcNow, message,
                                         string.IsNullOrEmpty(Thread.CurrentThread.Name) ? Thread.CurrentThread.ManagedThreadId.ToString() : Thread.CurrentThread.Name);

                    TraceReceived(new TraceMessageEventArgs(traceMessage));
                }
            }
        }
        public static void Trace(TraceLevels type, string message, params object[] args)
        {
            lock (_syncRoot)
            {
                if (TraceReceived != null)
                {
                    if (args.Length > 0)
                    {
                        message = string.Format(message, args);
                    }

                    TraceMessage traceMessage =
                        new TraceMessage(type, DateTime.UtcNow, message,
                            string.IsNullOrEmpty(Thread.CurrentThread.Name) ? Thread.CurrentThread.ManagedThreadId.ToString() : Thread.CurrentThread.Name);

                    TraceReceived(new TraceMessageEventArgs(traceMessage));
                }
            }
        }
Beispiel #4
0
        public override async Task ProcessAsync(ArraySegment <Byte> data)
        {
            try
            {
                var dataString = System.Text.Encoding.UTF8.GetString(data);
                this.TraceLevel = Enum.Parse <TraceLevels>(dataString, true);
                this.logger.Info($"Pending transaction tracing level set to {this.TraceLevel}");
                await Task.CompletedTask;
            }
            catch (Exception exception)
            {
                await this.SendRawAsync($"Exception occurred while processing request: {exception.Message}");

                this.logger.Info($"Exception occurred while processing Pending WebSocket request:");
                // optimistically try to log the failing incoming message as a string, if it fails move on
                try { this.logger.Info(System.Text.Encoding.UTF8.GetString(data)); } catch { }
                this.logger.Info(exception.Message);
                this.logger.Info(exception.StackTrace);
            }
        }
Beispiel #5
0
        static Tracer()
        {
            TracerConfigurationSection config = ConfigurationManager.GetSection("traceListeners") as TracerConfigurationSection;

            if (config == null)
            {
                return;
            }

            foreach (TracerElement tracer in config.Tracers)
            {
                Type type = Type.GetType(tracer.Type);

                if (type == null)
                {
                    Tracer.Warn("Unable to resolve type \"{0}\"", tracer.Type);
                    continue;
                }

                TraceLevels traceLevel = TraceLevels.Verbose;

                if (!string.IsNullOrEmpty(tracer.TraceLevel))
                {
                    if (!Enum.IsDefined(typeof(TraceLevels), tracer.TraceLevel))
                    {
                        Tracer.Warn("Unable to resolve Trace Level \"{0}\"", tracer.TraceLevel);
                    }
                    else
                    {
                        traceLevel = (TraceLevels)Enum.Parse(typeof(TraceLevels), tracer.TraceLevel);
                    }
                }

                ITraceListener listener = Activator.CreateInstance(type) as ITraceListener;

                if (listener != null)
                {
                    listener.TraceLevel = traceLevel;
                }
            }
        }
        /// <summary>
        /// Logs the specified trace levels.
        /// </summary>
        /// <param name="traceLevel">The trace levels.</param>
        /// <param name="message">The message.</param>
        /// <param name="subject">The subject.</param>
        /// <param name="messageType">Type of the message.</param>
        /// <param name="stackTrace">The stack trace.</param>
        /// <returns></returns>
        public IProcessResult Log(TraceLevels traceLevel, string message, string subject, MessageTypes messageType, string stackTrace)
        {
            ApplicationLog applicationLog = new ApplicationLog()
            {
                JSUserId      = SecurityManager.Current.UserId,
                Message       = message,
                Subject       = subject,
                MessageTypeId = (int)messageType,
                TrackingGuid  = SecurityManager.Current.TrackingGuid,
                ApplicationId = (int)SecurityManager.Current.CurrentApplication,
                StackTrace    = stackTrace,
                TraceLevelId  = (int)traceLevel
            };

            BackgroundProcessHelper.Current.Trigger(async(cancelationToken) =>
            {
                await InsertAsync(new ConnectionInfo(SystemUsers.Admin), applicationLog);
            });

            return(new ProcessResult(ResultCodes.Success));
        }
 public void Trace(TraceLevels level, string format, params object[] args)
 {
     lock (_traceLock)
     {
         if (TraceLevel.HasFlag(level))
         {
             _traceWriter.WriteLine(
                 DateTime.UtcNow.ToString("HH:mm:ss.fffffff", CultureInfo.InvariantCulture) + " - " +
                     (ConnectionId ?? "null") + " - " +
                     format,
                 args);
         }
     }
 }
Beispiel #8
0
        //
        // Only for use by ObjectAdapterFactory
        //
        public ObjectAdapterI(Instance instance, Communicator communicator,
                              ObjectAdapterFactory objectAdapterFactory, string name,
                              RouterPrx router, bool noConfig)
        {
            instance_             = instance;
            _communicator         = communicator;
            _objectAdapterFactory = objectAdapterFactory;
            _servantManager       = new ServantManager(instance, name);
            _name = name;
            _incomingConnectionFactories = new List <IncomingConnectionFactory>();
            _publishedEndpoints          = new List <EndpointI>();
            _routerEndpoints             = new List <EndpointI>();
            _routerInfo  = null;
            _directCount = 0;
            _noConfig    = noConfig;

            if (_noConfig)
            {
                _id             = "";
                _replicaGroupId = "";
                _reference      = instance_.referenceFactory().create("dummy -t", "");
                _acm            = instance_.serverACM();
                return;
            }

            Properties    properties   = instance_.initializationData().properties;
            List <string> unknownProps = new List <string>();
            bool          noProps      = filterProperties(unknownProps);

            //
            // Warn about unknown object adapter properties.
            //
            if (unknownProps.Count != 0 && properties.getPropertyAsIntWithDefault("Ice.Warn.UnknownProperties", 1) > 0)
            {
                StringBuilder message = new StringBuilder("found unknown properties for object adapter `");
                message.Append(_name);
                message.Append("':");
                foreach (string s in unknownProps)
                {
                    message.Append("\n    ");
                    message.Append(s);
                }
                instance_.initializationData().logger.warning(message.ToString());
            }

            //
            // Make sure named adapter has configuration.
            //
            if (router == null && noProps)
            {
                //
                // These need to be set to prevent warnings/asserts in the destructor.
                //
                state_    = StateDestroyed;
                instance_ = null;
                _incomingConnectionFactories = null;

                InitializationException ex = new InitializationException();
                ex.reason = "object adapter `" + _name + "' requires configuration";
                throw ex;
            }

            _id             = properties.getProperty(_name + ".AdapterId");
            _replicaGroupId = properties.getProperty(_name + ".ReplicaGroupId");

            //
            // Setup a reference to be used to get the default proxy options
            // when creating new proxies. By default, create twoway proxies.
            //
            string proxyOptions = properties.getPropertyWithDefault(_name + ".ProxyOptions", "-t");

            try
            {
                _reference = instance_.referenceFactory().create("dummy " + proxyOptions, "");
            }
            catch (ProxyParseException)
            {
                InitializationException ex = new InitializationException();
                ex.reason = "invalid proxy options `" + proxyOptions + "' for object adapter `" + _name + "'";
                throw ex;
            }

            _acm = new ACMConfig(properties, communicator.getLogger(), _name + ".ACM", instance_.serverACM());

            {
                int defaultMessageSizeMax = instance.messageSizeMax() / 1024;
                int num = properties.getPropertyAsIntWithDefault(_name + ".MessageSizeMax", defaultMessageSizeMax);
                if (num < 1 || num > 0x7fffffff / 1024)
                {
                    _messageSizeMax = 0x7fffffff;
                }
                else
                {
                    _messageSizeMax = num * 1024; // Property is in kilobytes, _messageSizeMax in bytes
                }
            }

            try
            {
                int threadPoolSize    = properties.getPropertyAsInt(_name + ".ThreadPool.Size");
                int threadPoolSizeMax = properties.getPropertyAsInt(_name + ".ThreadPool.SizeMax");
                if (threadPoolSize > 0 || threadPoolSizeMax > 0)
                {
                    _threadPool = new ThreadPool(instance_, _name + ".ThreadPool", 0);
                }

                if (router == null)
                {
                    router = RouterPrxHelper.uncheckedCast(
                        instance_.proxyFactory().propertyToProxy(_name + ".Router"));
                }
                if (router != null)
                {
                    _routerInfo = instance_.routerManager().get(router);
                    if (_routerInfo != null)
                    {
                        //
                        // Make sure this router is not already registered with another adapter.
                        //
                        if (_routerInfo.getAdapter() != null)
                        {
                            Ice.AlreadyRegisteredException ex = new Ice.AlreadyRegisteredException();
                            ex.kindOfObject = "object adapter with router";
                            ex.id           = Ice.Util.identityToString(router.ice_getIdentity());
                            throw ex;
                        }

                        //
                        // Add the router's server proxy endpoints to this object
                        // adapter.
                        //
                        EndpointI[] endpoints = _routerInfo.getServerEndpoints();
                        for (int i = 0; i < endpoints.Length; ++i)
                        {
                            _routerEndpoints.Add(endpoints[i]);
                        }
                        _routerEndpoints.Sort(); // Must be sorted.

                        //
                        // Remove duplicate endpoints, so we have a list of unique endpoints.
                        //
                        for (int i = 0; i < _routerEndpoints.Count - 1;)
                        {
                            EndpointI e1 = _routerEndpoints[i];
                            EndpointI e2 = _routerEndpoints[i + 1];
                            if (e1.Equals(e2))
                            {
                                _routerEndpoints.RemoveAt(i);
                            }
                            else
                            {
                                ++i;
                            }
                        }

                        //
                        // Associate this object adapter with the router. This way,
                        // new outgoing connections to the router's client proxy will
                        // use this object adapter for callbacks.
                        //
                        _routerInfo.setAdapter(this);

                        //
                        // Also modify all existing outgoing connections to the
                        // router's client proxy to use this object adapter for
                        // callbacks.
                        //
                        instance_.outgoingConnectionFactory().setRouterInfo(_routerInfo);
                    }
                }
                else
                {
                    //
                    // Parse the endpoints, but don't store them in the adapter. The connection
                    // factory might change it, for example, to fill in the real port number.
                    //
                    List <EndpointI> endpoints = parseEndpoints(properties.getProperty(_name + ".Endpoints"), true);
                    foreach (EndpointI endp in endpoints)
                    {
                        IncomingConnectionFactory factory = new IncomingConnectionFactory(instance, endp, this);
                        _incomingConnectionFactories.Add(factory);
                    }
                    if (endpoints.Count == 0)
                    {
                        TraceLevels tl = instance_.traceLevels();
                        if (tl.network >= 2)
                        {
                            instance_.initializationData().logger.trace(tl.networkCat, "created adapter `" + _name +
                                                                        "' without endpoints");
                        }
                    }

                    //
                    // Parse published endpoints.
                    //
                    _publishedEndpoints = parsePublishedEndpoints();
                }

                if (properties.getProperty(_name + ".Locator").Length > 0)
                {
                    setLocator(LocatorPrxHelper.uncheckedCast(
                                   instance_.proxyFactory().propertyToProxy(_name + ".Locator")));
                }
                else
                {
                    setLocator(instance_.referenceFactory().getDefaultLocator());
                }
            }
            catch (LocalException)
            {
                destroy();
                throw;
            }
        }
Beispiel #9
0
 /// <summary>
 /// set Tracelevel and tracefile to be used with hub trace
 /// </summary>
 /// <param name="level">tracelevel for hubtrace</param>
 /// <param name="traceFile">filepath to be used for5 hubtrace</param>
 public void SetTrace(TraceLevel level, string traceFile)
 {
     m_Trace     = (TraceLevels)level;
     m_TraceFile = traceFile.Replace("#", "-");
     SetTrace();
 }
Beispiel #10
0
 public void Trace(TraceLevels level, string format, params object[] args)
 {
     _invocationManager.AddInvocation("Trace", level, format, args);
 }
Beispiel #11
0
 /// <summary>
 /// Sends an Application Message
 /// </summary>
 /// <param name="messageType">Type of the message.</param>
 /// <param name="message">The message.</param>
 /// <param name="subject">The subject.</param>
 /// <param name="traceLevel">The trace level.</param>
 /// <param name="stackTrace">The stack trace.</param>
 /// <returns></returns>
 public async Task <IProcessResult> Send(MessageTypes messageType, string message, string subject = null, TraceLevels traceLevel = TraceLevels.Information, string stackTrace = null)
 {
     return(await Send(new AppMessage()
     {
         Subject = subject, Message = message, MessageType = messageType, TraceLevel = traceLevel, StackTrace = stackTrace
     }));
 }
Beispiel #12
0
 public static bool HasFlag(this TraceLevels @this, TraceLevels traceLevels)
 {
     return ((int)@this & (int)traceLevels) == (int)traceLevels;
 }
 public IReliableSignalRClient UseTracer(TextWriter textWritter, TraceLevels traceLevel = TraceLevels.All)
 {
     _tracer     = textWritter;
     _traceLevel = traceLevel;
     return(this);
 }
Beispiel #14
0
        /// <summary>
        /// Traces the message.
        /// </summary>
        /// <param name="traceLevel">The trace level.</param>
        /// <param name="message">The message.</param>
        /// <param name="subject">The subject.</param>
        /// <param name="messageType">Type of the message.</param>
        /// <param name="stackTrace">The stack trace.</param>
        /// <returns></returns>
        public IProcessResult TraceMessage(TraceLevels traceLevel, string message, string subject = null, string messageType = null, string stackTrace = null)
        {
            ILog log = LogManager.GetLogger("TraceLog");

            List <string> messageParts = new List <string>();

            if (!String.IsNullOrEmpty(messageType))
            {
                messageParts.Add(messageType);
            }

            if (!String.IsNullOrEmpty(subject))
            {
                messageParts.Add(subject);
            }

            if (!String.IsNullOrEmpty(message))
            {
                messageParts.Add(message);
            }

            string traceMessage = String.Join(" - ", messageParts);

            if (!String.IsNullOrEmpty(stackTrace))
            {
                traceMessage += String.Format("\n{0}", stackTrace);
            }

            switch (traceLevel)
            {
            case TraceLevels.Fatal:

                log.Fatal(traceMessage);
                break;

            case TraceLevels.Error:

                log.Error(traceMessage);
                break;

            case TraceLevels.Warning:

                log.Warn(traceMessage);
                break;

            case TraceLevels.Information:

                log.Info(traceMessage);
                break;

            case TraceLevels.Debug:

                log.Debug(traceMessage);
                break;

            default:
                break;
            }

            return(new ProcessResult(ResultCodes.Success));
        }