Ejemplo n.º 1
0
        private void ThisAddInStartup(object sender, EventArgs e)
        {
            try
            {
                var loggingKeyDown = false;
                var currentDomain  = AppDomain.CurrentDomain;
                currentDomain.AssemblyResolve    += currentDomain_AssemblyResolve;
                currentDomain.UnhandledException += CurrentDomain_UnhandledException;

                var levelSwitch = new Serilog.Core.LoggingLevelSwitch(Serilog.Events.LogEventLevel.Error);
                var config      = new LoggerConfiguration()
                                  .ReadFrom.AppSettings()
                                  .MinimumLevel.ControlledBy(levelSwitch);;

                if (System.Windows.Input.Keyboard.IsKeyDown(Constants.LoggingHotKey1) ||
                    System.Windows.Input.Keyboard.IsKeyDown(Constants.LoggingHotKey2))
                {
                    loggingKeyDown   = true;
                    _debugLogEnabled = true;

                    // increase the default log level when the logging hot key is held down
                    levelSwitch.MinimumLevel = Serilog.Events.LogEventLevel.Debug;
                    Log.Debug("Debug Logging Enabled");

                    // force logging to rolling log file (in case the app settings has switched this off)
                    var logPath = Path.Combine(ApplicationPaths.LogPath
                                               , Constants.ExcelLogFileName);
                    config.WriteTo.File(logPath, restrictedToMinimumLevel: Serilog.Events.LogEventLevel.Debug, retainedFileCountLimit: 10);
                }
                log        = config.CreateLogger();
                Log.Logger = log;
                Log.Information("============ Excel Add-in Startup =============");
                ExcelInfo.WriteToLog(this);
                if (loggingKeyDown)
                {
                    if (_ribbon != null)
                    {
                        _ribbon.DebugLoggingEnabled = true;
                    }
                    Log.Information($"Logging enabled by {Constants.LoggingHotKeyName} Key at startup");
                }
                CreateRibbonObjects();
            } catch (Exception ex)
            {
                CrashReporter.ReportCrash(ex, "DAX Studio Excel Addin fatal startup exception");
            }
        }
Ejemplo n.º 2
0
        private void ThisAddInStartup(object sender, EventArgs e)
        {
            try
            {
                var loggingKeyDown = false;
                var currentDomain  = AppDomain.CurrentDomain;
                currentDomain.AssemblyResolve    += currentDomain_AssemblyResolve;
                currentDomain.UnhandledException += CurrentDomain_UnhandledException;

                var config = new LoggerConfiguration().ReadFrom.AppSettings();
                if (System.Windows.Input.Keyboard.IsKeyDown(Constants.LoggingHotKey1) ||
                    System.Windows.Input.Keyboard.IsKeyDown(Constants.LoggingHotKey2))
                {
                    loggingKeyDown   = true;
                    _debugLogEnabled = true;
                    var logPath = Path.Combine(Environment.ExpandEnvironmentVariables(Constants.LogFolder)
                                               , Constants.ExcelLogFileName);
                    config.WriteTo.RollingFile(logPath, restrictedToMinimumLevel: Serilog.Events.LogEventLevel.Debug, retainedFileCountLimit: 10);
                }
                log        = config.CreateLogger();
                Log.Logger = log;
                Log.Information("============ Excel Add-in Startup =============");
                ExcelInfo.WriteToLog(this);
                if (loggingKeyDown)
                {
                    if (_ribbon != null)
                    {
                        _ribbon.DebugLoggingEnabled = true;
                    }
                    Log.Information($"Logging enabled by {Constants.LoggingHotKeyName} Key at startup");
                }
                CreateRibbonObjects();
            } catch (Exception ex)
            {
                CrashReporter.ReportCrash(ex, "DAX Studio Excel Addin fatal startup exception");
            }
        }