예제 #1
0
        public void SystemAndActorLogUsingNLogLoggingForAkka()
        {
            var config = ConfigurationFactory.ParseString(@"akka {
    loggers = [""Akka.Logger.NLog.NLogLogger, Akka.Logger.NLog""]
    loglevel = info
    log-config-on-start = off
    stdout-loglevel = off
    actor {
      debug {
        receive = on      # log any received message
        autoreceive = on  # log automatically received messages, e.g. PoisonPill
        lifecycle = on    # log actor lifecycle changes
        event-stream = on # log subscription changes for Akka.NET event stream
        unhandled = on    # log unhandled messages sent to actors
      }
    }
}");

            lock (Locker.Instance)
            {
                ConfigureNlog();

                if (File.Exists(LogPath))
                {
                    File.Delete(LogPath);
                }

                var actorSystem = ActorSystem.Create("MyActorSystem", config);
                var logger      = Logging.GetLogger(actorSystem, actorSystem);
                logger.Info("Actor system created.");
                var loggingActor = actorSystem.ActorOf <LoggingActor>();
                logger.Info("Echo logging actor created.");
                loggingActor.Tell("Log this message, please.");
                loggingActor.Tell(new NullReferenceException());

                var logContent = ActorTests.WaitForFileContentAsync("Log this message, please.", LogPath, TimeSpan.FromSeconds(30)).Result;
                Assert.Contains("Actor system created.", logContent);
                Assert.Contains("Log this message, please.", logContent);
            }
        }
        public void ActorLogsViaAspectOrientedDiagnostics()
        {
            var config = ConfigurationFactory.ParseString(@"akka {
    loggers = [""Akka.Logger.Extensions.Logging.LoggingLogger, Akka.Logger.Extensions.Logging""]
    loglevel = info
    log-config-on-start = off
    stdout-loglevel = off
    actor {
      debug {
        receive = on      # log any received message
        autoreceive = on  # log automatically received messages, e.g. PoisonPill
        lifecycle = on    # log actor lifecycle changes
        event-stream = on # log subscription changes for Akka.NET event stream
        unhandled = on    # log unhandled messages sent to actors
      }
    }
}");

            lock (Locker.Instance)
            {
                ConfigureNlog();

                if (File.Exists(LogPath))
                {
                    File.Delete(LogPath);
                }

                var actorSystem           = ActorSystem.Create("ActorSystem", config).UseServiceProvider(_serviceProvider);
                var actorUnawareOfLogging = actorSystem.ActorOf(actorSystem.DI().Props <ActorUnawareOfLogging>());

                string expectedMsg = "This message should be logged by the interceptor.";

                actorUnawareOfLogging.Tell(expectedMsg);

                var logContent = ActorTests.WaitForFileContentAsync(expectedMsg, LogPath, TimeSpan.FromSeconds(20)).Result;
                Assert.Contains(expectedMsg, logContent);
            }
        }