/// <summary>
        /// Create a serilog trace logger which replaces the default logging.
        /// </summary>
        /// <param name="loggerConfiguration">The logger configuration.</param>
        /// <param name="config">The application configuration.</param>
        /// <param name="fileMinimumLevel">The min log level for file output.</param>
        public static SerilogTraceLogger Create(
            LoggerConfiguration loggerConfiguration,
            ApplicationConfiguration config,
            LogEventLevel fileMinimumLevel = LogEventLevel.Information)
        {
            if (loggerConfiguration == null)
            {
                loggerConfiguration = new LoggerConfiguration();
            }
            // add file logging
            if (!string.IsNullOrWhiteSpace(config.TraceConfiguration.OutputFilePath))
            {
                loggerConfiguration.WriteTo.File(
                    Utils.ReplaceSpecialFolderNames(config.TraceConfiguration.OutputFilePath),
                    rollingInterval: RollingInterval.Day,
                    rollOnFileSizeLimit: true,
                    restrictedToMinimumLevel: fileMinimumLevel,
                    retainedFileCountLimit: 10,
                    flushToDiskInterval: TimeSpan.FromSeconds(13));
            }

            ILogger logger = loggerConfiguration
                             .MinimumLevel.Information()
                             .CreateLogger();

            SerilogTraceLogger traceLogger = new SerilogTraceLogger(logger, config.TraceConfiguration.TraceMasks);

            // disable the built in tracing, use serilog
            Utils.SetTraceMask(Utils.TraceMask & Utils.TraceMasks.StackTrace);
            Utils.SetTraceOutput(Utils.TraceOutput.Off);
            Utils.Tracing.TraceEventHandler += traceLogger.TraceEventHandler;

            return(traceLogger);
        }
Example #2
0
        static void Main()
        {
            // Initialize the user interface.
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);

            ApplicationInstance.MessageDlg = new ApplicationMessageDlg();
            ApplicationInstance application = new ApplicationInstance();

            application.ApplicationType   = ApplicationType.Server;
            application.ConfigSectionName = "Quickstarts.ReferenceServer";

            try
            {
                // load the application configuration.
                ApplicationConfiguration config = application.LoadApplicationConfiguration(false).Result;

                LoggerConfiguration loggerConfiguration = new LoggerConfiguration();
#if DEBUG
                loggerConfiguration.WriteTo.Debug(restrictedToMinimumLevel: Serilog.Events.LogEventLevel.Warning);
#endif
                SerilogTraceLogger.Create(loggerConfiguration, config);

                // check the application certificate.
                bool certOk = application.CheckApplicationInstanceCertificate(false, 0).Result;
                if (!certOk)
                {
                    throw new Exception("Application instance certificate invalid!");
                }

                // Create server, add additional node managers
                var server = new ReferenceServer();
                Quickstarts.Servers.Utils.AddDefaultNodeManagers(server);

                // start the server.
                application.Start(server).Wait();

                // check whether the invalid certificates dialog should be displayed.
                bool showCertificateValidationDialog = false;
                ReferenceServerConfiguration refServerconfiguration = application.ApplicationConfiguration.ParseExtension <ReferenceServerConfiguration>();

                if (refServerconfiguration != null)
                {
                    showCertificateValidationDialog = refServerconfiguration.ShowCertificateValidationDialog;
                }

                // run the application interactively.
                Application.Run(new ServerForm(application, showCertificateValidationDialog));
            }
            catch (Exception e)
            {
                ExceptionDlg.Show(application.ApplicationName, e);
            }
        }
Example #3
0
        private async Task StartConsoleReferenceServerAsync()
        {
            ApplicationInstance.MessageDlg = new ApplicationMessageDlg();
            CertificatePasswordProvider PasswordProvider = new CertificatePasswordProvider(Password);
            ApplicationInstance         application      = new ApplicationInstance {
                ApplicationName             = "Quickstart Reference Server",
                ApplicationType             = ApplicationType.Server,
                ConfigSectionName           = Utils.IsRunningOnMono() ? "Quickstarts.MonoReferenceServer" : "Quickstarts.ReferenceServer",
                CertificatePasswordProvider = PasswordProvider
            };

            // load the application configuration.
            ApplicationConfiguration config = await application.LoadApplicationConfiguration(false).ConfigureAwait(false);

            var loggerConfiguration = new Serilog.LoggerConfiguration();

            if (LogConsole)
            {
                loggerConfiguration.WriteTo.Console(restrictedToMinimumLevel: Serilog.Events.LogEventLevel.Warning);
            }
#if DEBUG
            else
            {
                loggerConfiguration.WriteTo.Debug(restrictedToMinimumLevel: Serilog.Events.LogEventLevel.Warning);
            }
#endif
            SerilogTraceLogger.Create(loggerConfiguration, config);

            // check the application certificate.
            bool haveAppCertificate = await application.CheckApplicationInstanceCertificate(
                false, CertificateFactory.DefaultKeySize, CertificateFactory.DefaultLifeTime).ConfigureAwait(false);

            if (!haveAppCertificate)
            {
                throw new Exception("Application instance certificate invalid!");
            }

            if (!config.SecurityConfiguration.AutoAcceptUntrustedCertificates)
            {
                config.CertificateValidator.CertificateValidation += new CertificateValidationEventHandler(CertificateValidator_CertificateValidation);
            }

            // start the server.
            m_server = new ReferenceServer();
            await application.Start(m_server).ConfigureAwait(false);

            // print endpoint info
            var endpoints = application.Server.GetEndpoints().Select(e => e.EndpointUrl).Distinct();
            foreach (var endpoint in endpoints)
            {
                Console.WriteLine(endpoint);
            }

            // start the status thread
            m_status = Task.Run(new Action(StatusThreadAsync));

            // print notification on session events
            m_server.CurrentInstance.SessionManager.SessionActivated += EventStatus;
            m_server.CurrentInstance.SessionManager.SessionClosing   += EventStatus;
            m_server.CurrentInstance.SessionManager.SessionCreated   += EventStatus;
        }