本文整理汇总了C#中Logger.FatalException方法的典型用法代码示例。如果您正苦于以下问题:C# Logger.FatalException方法的具体用法?C# Logger.FatalException怎么用?C# Logger.FatalException使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Logger
的用法示例。
在下文中一共展示了Logger.FatalException方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: SetupNLog
private static void SetupNLog()
{
// Create a Logger
logger = LogManager.GetCurrentClassLogger();
// Add the event handler for handling non-UI thread exceptions
AppDomain.CurrentDomain.UnhandledException += (s, e) =>
{
var exception = (Exception)e.ExceptionObject;
logger.FatalException("Report Designer encountered unhandled exception", exception);
};
}
示例2: OnStartup
protected override void OnStartup(StartupEventArgs e)
{
_logger = NLog.LogManager.GetCurrentClassLogger();
Application.Current.Dispatcher.UnhandledException += (sender, args) =>
{
_logger.FatalException("UnhandledException", args.Exception);
};
var bootstrapper = new AppBootstrapper();
_openShellViewSubscription = bootstrapper.OnStartUp.ObserveOnDispatcher().Subscribe(c =>
{
c.Resolve<Shell>().Show();
});
}
示例3: Init
public void Init(string dirName, string parentProcessId)
{
try
{
var exeDir = new DirectoryInfo(AppDomain.CurrentDomain.BaseDirectory).Parent.Parent.FullName;
GlobalDiagnosticsContext.Set("ExeBaseDir", exeDir);
GlobalDiagnosticsContext.Set("SubDirName", dirName);
GlobalDiagnosticsContext.Set("ParentProcess", parentProcessId);
ConfigurationItemFactory.Default.Targets.RegisterDefinition("ServiceManager", typeof(ServiceManagerTarget));
ConfigurationItemFactory.Default.Targets.RegisterDefinition("ServiceManagerNotification", typeof(NLog.Targets.NullTarget));
_dirName = dirName;
_logger = LogManager.GetCurrentClassLogger();
AppDomain.CurrentDomain.UnhandledException += OnAppDomainUnhandledException;
TaskScheduler.UnobservedTaskException += OnTaskSchedulerUnobservedTaskException;
var list = new List<ExtensionInfo>();
var files = new DirectoryInfo(AppDomain.CurrentDomain.BaseDirectory).GetFiles("*.dll");
var asmExclusionsPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "loader.exclude.txt");
var exclusions = new HashSet<string>();
if (File.Exists(asmExclusionsPath))
exclusions = new HashSet<string>(
File.ReadAllLines(asmExclusionsPath)
.Select(s => Path.Combine(AppDomain.CurrentDomain.BaseDirectory, s).ToLower())
.Where(File.Exists));
foreach (var file in files)
{
if (exclusions.Contains(file.FullName.ToLower()))
continue;
try
{
var asm = Assembly.Load(Path.GetFileNameWithoutExtension(file.Name));
var types = (from t in asm.GetTypes()
where t.GetInterfaces().Any(i => i == typeof(IServerExtension)) && t.IsClass && !t.IsAbstract && t.GetConstructors().Where(i => i.GetParameters().Count() == 0).Any()
select t);
var typeMap = (from t in types
select new { Ext = (IServerExtension)Activator.CreateInstance(t) }).ToDictionary(k => k.Ext.ID, v => v.Ext);
list.AddRange(
typeMap.Values.Select(ext => new ExtensionInfo
{
ExtensionID = ext.ID,
Name = ext.Name,
Description = ext.Description,
AssemblyQualifiedName = ext.GetType().AssemblyQualifiedName
})
);
}
catch (ReflectionTypeLoadException ex)
{
_logger.Warn("Unable to load: " + file.Name);
foreach(var lx in ex.LoaderExceptions)
_logger.Warn(" => " + lx.Message);
continue;
}
catch (BadImageFormatException)
{
continue;
}
}
_infos = list.ToArray();
_logger.Info("Obtained info for " + _infos.Length + " available extensions");
}
catch (Exception ex)
{
_logger.FatalException("Exception while activating exception: ", ex);
Console.WriteLine(ex.ToString());
throw;
}
}
示例4: SetupNLog
private static void SetupNLog()
{
//write config file to the root!
//gcXtraReports.Designer
using (var stream = typeof(Program).Assembly.GetManifestResourceStream("GeniusCode.XtraReports.Designer.NLog.config"))
{
if (File.Exists("NLog.config"))
File.Delete("NLog.config");
using (var fs = File.Create("NLog.config"))
{
stream.CopyTo(fs);
fs.Flush();
}
}
//ConfigurationItemFactory.Default.Targets.RegisterDefinition("MessagePublishingTarget", typeof(MessagePublishingTarget));
// Create a Logger
//var target = new MessagePublishingTarget();
//ogManager.Configuration.AddTarget("MessagePublishingTarget", target);
//ogManager.Configuration.LoggingRules.Add(new LoggingRule("*", LogLevel.Trace, target));
_logger = LogManager.GetCurrentClassLogger();
var logPath = Path.Combine(Path.GetTempPath(), "gcXtraReport.Designer");
if (!Directory.Exists(logPath))
Directory.CreateDirectory(logPath);
string fileName = string.Format("text-{0:yyyy-MM-dd_hh-mm-ss-tt}.txt", DateTime.Now);
GlobalDiagnosticsContext.Set("logdir", logPath);
GlobalDiagnosticsContext.Set("logfilename", fileName);
LogPath = logPath + "\\" + fileName;
// Add the event handler for handling non-UI thread exceptions
AppDomain.CurrentDomain.UnhandledException += (s, e) =>
{
var exception = (Exception)e.ExceptionObject;
_logger.FatalException("Report Designer encountered unhandled exception", exception);
MessageBox.Show("An exception has occured. Please check the log file at:" + LogPath);
};
}
示例5: SetupNLog
private static void SetupNLog()
{
// Create a Logger
logger = LogManager.GetCurrentClassLogger();
logger.Info("Starting razor console...");
// Add the event handler for handling non-UI thread exceptions
AppDomain.CurrentDomain.UnhandledException += (s, e) =>
{
const string message = "Razor Console encountered unhandled exception";
var exception = (Exception)e.ExceptionObject;
logger.FatalException(message, exception);
// Build VisualStudio-Aware Exception
var errorString = ConsoleHelper.CreateVisualStudioErrorString("gcRazorConsole", "-200", string.Format("{0} : {1}",message, exception.ToString()));
Console.WriteLine(errorString);
};
}