/// <summary>
        /// This is the entry point of the service host process.
        /// </summary>
        private static void Main()
        {
            ILogger logger = null;

            try
            {
                // This line registers an Actor Service to host your actor class with the Service Fabric runtime.
                // The contents of your ServiceManifest.xml and ApplicationManifest.xml files
                // are automatically populated when you build this project.
                // For more information, see https://aka.ms/servicefabricactorsplatform

                ActorRuntime.RegisterActorAsync <MyActor>((context, actorType) =>
                {
                    var applicationInsightsKey = FabricRuntime.GetActivationContext()
                                                 .GetConfigurationPackageObject("Config")
                                                 .Settings
                                                 .Sections["ConfigurationSection"]
                                                 .Parameters["ApplicationInsightsKey"]
                                                 .Value;

                    var loggerFactory = new LoggerFactoryBuilder(context).CreateLoggerFactory(applicationInsightsKey);
                    logger            = loggerFactory.CreateLogger <MyActor>();

                    return(ActorServiceFactory.CreateActorService(context, actorType, logger, (service, id) => new MyActor(service, id, logger)));
                }).GetAwaiter().GetResult();

                Thread.Sleep(Timeout.Infinite);
            }
            catch (Exception e)
            {
                logger?.LogActorHostInitalizationFailed <MyActor>(e);
                throw;
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// This is the entry point of the service host process.
        /// </summary>
        private static void Main()
        {
            ILogAs logAs = null;

            var applicationInsightsKey = FabricRuntime.GetActivationContext()?
                                         .GetConfigurationPackageObject(Consts.Config.ConfigurationPackageObject)?
                                         .Settings.Sections[Consts.Config.ApplicationInsights.Section]?
                                         .Parameters[Consts.Config.ApplicationInsights.Param]?.Value;

            try
            {
                // The ServiceManifest.XML file defines one or more service type names.
                // Registering a service maps a service type name to a .NET type.
                // When Service Fabric creates an instance of this service type,
                // an instance of the class is created in this host process.

                ServiceRuntime.RegisterServiceAsync("ITG.Brix.WorkOrders.APIType",
                                                    context =>
                {
                    var loggerFactory = new LoggerFactoryBuilder(context).CreateLoggerFactory(applicationInsightsKey);
                    var logger        = loggerFactory.CreateLogger <ApiStatelessService>();
                    logAs             = new LogAs(logger);
                    return(new ApiStatelessService(context, loggerFactory, logAs));
                }).GetAwaiter().GetResult();
                ServiceEventSource.Current.ServiceTypeRegistered(Process.GetCurrentProcess().Id, typeof(ApiStatelessService).Name);

                // Prevents this host process from terminating so services keeps running.
                Thread.Sleep(Timeout.Infinite);
            }
            catch (Exception ex)
            {
                logAs?.ServiceInitalizationFailed(typeof(ApiStatelessService).FullName, ex);
                throw;
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// This is the entry point of the service host process.
        /// </summary>
        private static void Main()
        {
            ILogger logger = null;

            var applicationInsightsKey = FabricRuntime.GetActivationContext()
                                         .GetConfigurationPackageObject("Config")
                                         .Settings
                                         .Sections["ConfigurationSection"]
                                         .Parameters["ApplicationInsightsKey"]
                                         .Value;

            try
            {
                // The ServiceManifest.XML file defines one or more service type names.
                // Registering a service maps a service type name to a .NET type.
                // When Service Fabric creates an instance of this service type,
                // an instance of the class is created in this host process.

                ServiceRuntime.RegisterServiceAsync("WebApiType",
                                                    context =>
                {
                    LogContext.PushProperty(nameof(context.ServiceTypeName), context.ServiceTypeName);
                    LogContext.PushProperty(nameof(context.ServiceName), context.ServiceName);
                    LogContext.PushProperty(nameof(context.PartitionId), context.PartitionId);
                    LogContext.PushProperty(nameof(context.ReplicaOrInstanceId), context.ReplicaOrInstanceId);
                    LogContext.PushProperty(nameof(context.NodeContext.NodeName), context.NodeContext.NodeName);
                    LogContext.PushProperty(nameof(context.CodePackageActivationContext.ApplicationName), context.CodePackageActivationContext.ApplicationName);
                    LogContext.PushProperty(nameof(context.CodePackageActivationContext.ApplicationTypeName), context.CodePackageActivationContext.ApplicationTypeName);
                    LogContext.PushProperty(nameof(context.CodePackageActivationContext.CodePackageVersion), context.CodePackageActivationContext.CodePackageVersion);

                    var loggerFactory = new LoggerFactoryBuilder(context).CreateLoggerFactory(applicationInsightsKey);
                    logger            = loggerFactory.CreateLogger <WebApi>();

                    return(new WebApi(context, logger));
                }).GetAwaiter().GetResult();

                // Prevents this host process from terminating so services keeps running.
                Thread.Sleep(Timeout.Infinite);
            }
            catch (Exception e)
            {
                logger?.LogStatelessServiceInitalizationFailed <WebApi>(e);
                throw;
            }
        }
Ejemplo n.º 4
0
 public static void AddUnityDebugLogger(this LoggerFactoryBuilder builder)
 {
     builder.AddLogger(new UnityDebugLogger());
 }