public void LoggerGenerateOutputTest()
        {
            Logger logger = new Logger(System.Reflection.Assembly.GetExecutingAssembly());
            logger.Exception("exception #1");
            logger.Exception("exception #2");
            logger.Exception("exception #3");
            logger.Exception("exception #4");

            logger.Error("Error 1");
            logger.Error("Error 2");
            logger.Error("Error 3");

            logger.Warn("Warn 1");
            logger.Warn("Warn 2");
            logger.Warn("Warn 3");

            string id = logger.LogResume();

            Assert.Pass(id);
        }
Example #2
0
        private static void ExampleTwo()
        {
            var simpleLayout = new SimpleLayout();

            var consoleAppender = new ConsoleAppender(simpleLayout);
            var fileAppender = new FileAppender(simpleLayout);
            fileAppender.File = "log.txt";

            var logger = new Logger(consoleAppender, fileAppender);
            logger.Error("Error parsing JSON.");
            logger.Info(string.Format("User {0} successfully registered.", "Pesho"));
            logger.Warn("Warning - missing files.");
        }
Example #3
0
        private static void ExampleFour()
        {
            var simpleLayout = new SimpleLayout();
            var consoleAppender = new ConsoleAppender(simpleLayout);
            consoleAppender.ReportLevel = ReportLevel.Error;

            var logger = new Logger(consoleAppender);

            logger.Info("Everything seems fine");
            logger.Warn("Warning: ping is too high - disconnect imminent");
            logger.Error("Error parsing request");
            logger.Critical("No connection string found in App.config");
            logger.Fatal("mscorlib.dll does not respond");
        }
Example #4
0
 public static void DispatchData(IDataProducer producer, object data, bool cloneDataOnFork, DispatchPolicy dispatchPolicy, 
     Set<IDataConsumer> dataConsumers, Logger logger)
 {
     if (data == null) { return; }
     if (dataConsumers.Count == 0)
     {
         if (logger != null) { logger.Warn("DispatchData", "Data ready but nobody is listening."); }
         return;
     }
     if (dispatchPolicy == DispatchPolicy.BalanceLoadSum || dispatchPolicy == DispatchPolicy.BalanceLoadMax)
     {
         if (logger != null) { logger.Trace("DispatchData", "Dispatching data of type {0} (load balancing) ...", data.GetType()); }
         int minLoad = int.MaxValue;
         IDataConsumer target = null;
         foreach (IDataConsumer consumer in dataConsumers)
         {
             int load = (dispatchPolicy == DispatchPolicy.BalanceLoadSum) ? GetBranchLoadSum(consumer) : GetBranchLoadMax(consumer);
             if (load < minLoad) { minLoad = load; target = consumer; }
         }
         target.ReceiveData(producer, data);
     }
     else if (dispatchPolicy == DispatchPolicy.Random)
     {
         if (logger != null) { logger.Trace("DispatchData", "Dispatching data of type {0} (random policy) ...", data.GetType()); }
         ArrayList<IDataConsumer> tmp = new ArrayList<IDataConsumer>(dataConsumers.Count);
         foreach (IDataConsumer dataConsumer in dataConsumers) { tmp.Add(dataConsumer); }
         tmp[mRandom.Next(0, tmp.Count)].ReceiveData(producer, data);
     }
     else
     {
         if (logger != null) { logger.Trace("DispatchData", "Dispatching data of type {0} (to-all policy) ...", data.GetType()); }
         if (dataConsumers.Count > 1 && cloneDataOnFork)
         {
             foreach (IDataConsumer dataConsumer in dataConsumers)
             {
                 dataConsumer.ReceiveData(producer, Utils.Clone(data, /*deepClone=*/true));
             }
         }
         else
         {
             foreach (IDataConsumer dataConsumer in dataConsumers)
             {
                 dataConsumer.ReceiveData(producer, data);
             }
         }
     }
     if (logger != null) { logger.Trace("DispatchData", "Data dispatched."); }
 }
Example #5
0
        public WlanClient()
        {
            ItsLogger = new Logger(this);

            try
            {
                Wlan.ThrowIfError(Wlan.WlanOpenHandle(1, IntPtr.Zero, out _negotiatedVersion, out _clientHandle));
                WlanNotificationCallback = new Wlan.WlanNotificationCallbackDelegate(OnWlanNotification);

                Wlan.WlanNotificationSource source;
                Wlan.ThrowIfError(Wlan.WlanRegisterNotification(_clientHandle, Wlan.WlanNotificationSource.All, false, WlanNotificationCallback, IntPtr.Zero, IntPtr.Zero, out source));
            }
            catch (Win32Exception ex)
            {
                Wlan.WlanCloseHandle(_clientHandle, IntPtr.Zero);
                ItsLogger.Warn(ex.Message);
                throw;
            }
        }
        private static GlobalSingleInstanceResponseOutcome? GetOutcome(ICollection<RemoteClusterActivationResponse> responses, GrainId grainId, Logger logger, bool hasPendingResponses)
        {
            if (!hasPendingResponses && responses.All(res => res.ResponseStatus == ActivationResponseStatus.Pass))
            {
                // All passed, or no other clusters exist
                return GlobalSingleInstanceResponseOutcome.Succeed;
            }

            var ownerResponses = responses
                .Where(res => res.ResponseStatus == ActivationResponseStatus.Failed && res.Owned == true).ToList();

            if (ownerResponses.Count > 0)
            {
                if (ownerResponses.Count > 1)
                    logger.Warn((int)ErrorCode.GlobalSingleInstance_MultipleOwners, "GSIP:Req {0} Unexpected error occured. Multiple Owner Replies.", grainId);

                return new GlobalSingleInstanceResponseOutcome(OutcomeState.RemoteOwner, ownerResponses[0].ExistingActivationAddress, ownerResponses[0].ClusterId);
            }

            // are all responses here or have failed?
            if (!hasPendingResponses)
            {
                // determine best candidate
                var candidates = responses
                    .Where(res => res.ResponseStatus == ActivationResponseStatus.Failed && res.ExistingActivationAddress.Address != null)
                    .ToList();

                AddressAndTag remoteOwner = new AddressAndTag();
                string remoteOwnerCluster = null;
                foreach (var res in candidates)
                {
                    if (remoteOwner.Address == null ||
                        MultiClusterUtils.ActivationPrecedenceFunc(grainId, res.ClusterId, remoteOwnerCluster))
                    {
                        remoteOwner = res.ExistingActivationAddress;
                        remoteOwnerCluster = res.ClusterId;
                    }
                }

                var outcome = remoteOwner.Address != null ? OutcomeState.RemoteOwnerLikely : OutcomeState.Inconclusive;
                return new GlobalSingleInstanceResponseOutcome(outcome, remoteOwner, remoteOwnerCluster);
            }

            return null;
        }
 /// <summary>
 /// <see cref="INoteManagerService.ListAllUsers"/>
 /// </summary>
 /// <param name="id"></param>
 public UserDTO[] ListAllUsers()
 {
     Logger logger = new Logger(this.GetType());
     logger.Debug("debug");
     logger.Error("error");
     logger.Info("info");
     logger.Warn("warn");
     using (var nme = new NoteManagerEntities())
     {
         var allUsers = from u in nme.User select u;
         List<UserDTO> res = new List<UserDTO>();
         foreach (var u in allUsers)
         {
             res.Add(new UserDTO(u));
         }
         return res.ToArray();
     }
 }