示例#1
0
        public static LoggerConfiguration Setup(RichTextBox textBox, string logPath = null)
        {
            try
            {
                string appName = typeof(Program).Namespace ?? "(default)";

                if (string.IsNullOrEmpty(logPath))
                {
                    // Log to 'GoodAI\Arnold\Logs'.
                    logPath = InitLogDirectory(appName.Replace('.', '\\'), "Logs");
                }

                return(SerilogRobeConfig.SetupLoggingToFile(logPath, appName)
                       .WriteTo.RichTextBox(textBox, maxTextLength: 10000, restrictedToMinimumLevel: LogEventLevel.Debug));
            }
            catch (Exception ex)
            {
                // TODO: Print inner exceptions and stack traces
                MessageBox.Show(
                    "Logging setup failed. The application will not log.\n\n" +
                    $"Attempted log path: {logPath}\n\nException message: {ex.Message}",
                    "Logging initialization error.", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            }

            return(null);
        }
示例#2
0
        public void Configure(Container container)
        {
            container.Options.PropertySelectionBehavior = new PropertyInjectionForType <ILog>(container);

            container.RegisterSingleton(new TestLogEventSink());

            container.RegisterSingleton(() => SerilogRobeConfig.Setup(config =>
                                                                      config.WriteTo.Sink(container.GetInstance <TestLogEventSink>())));

            container.RegisterConditional(
                typeof(ILog),
                typeFactory => typeof(SerilogRobe <>).MakeGenericType(typeFactory.Consumer.ImplementationType),
                Lifestyle.Singleton,
                predicateContext => true);

            container.Register <Fool>();
            container.Register <PropertyJester>();
            container.Register <PropertyMute>();
            container.Register <PropertyObject>();
        }