Added log4net-embedded.xml as embedded resource so Greenshot always has a log4net file. Also added ILMerge so we can make a Greenshot.exe without DLL's.

git-svn-id: http://svn.code.sf.net/p/greenshot/code/trunk@1606 7dccd23d-a4a3-4e1f-8c07-b4c1b4018ab4
This commit is contained in:
RKrom 2012-01-24 20:25:23 +00:00
commit 89c2b7a9e7
6 changed files with 158 additions and 12 deletions

View file

@ -20,6 +20,7 @@
*/
using System;
using System.IO;
using System.Reflection;
using System.Windows.Forms;
using log4net;
@ -38,22 +39,39 @@ namespace GreenshotPlugin.Core {
// Setup log4j, currently the file is called log4net.xml
string pafLog4NetFilename = Path.Combine(Application.StartupPath, @"App\Greenshot\" + LOG4NET_FILE);
string log4netFilename = Path.Combine(Application.StartupPath, LOG4NET_FILE);
bool isLog4NetConfigured = false;
if (File.Exists(log4netFilename)) {
XmlConfigurator.Configure(new FileInfo(log4netFilename));
try {
XmlConfigurator.Configure(new FileInfo(log4netFilename));
isLog4NetConfigured = true;
} catch {}
} else if (File.Exists(pafLog4NetFilename)) {
XmlConfigurator.Configure(new FileInfo(pafLog4NetFilename));
} else {
MessageBox.Show("Can't find file " + LOG4NET_FILE);
try {
XmlConfigurator.Configure(new FileInfo(pafLog4NetFilename));
isLog4NetConfigured = true;
} catch {}
}
if (!isLog4NetConfigured) {
try {
Assembly assem = typeof(LogHelper).Assembly;
using (Stream stream = assem.GetManifestResourceStream("GreenshotPlugin.log4net-embedded.xml")) {
XmlConfigurator.Configure(stream);
isLog4NetConfigured = true;
}
} catch {}
}
// Get the logfile
try {
IAppender appender = ((Hierarchy)LogManager.GetRepository()).Root.Appenders[0];
if (appender is FileAppender) {
return ((FileAppender)appender).File;
}
} catch (Exception) {
// Ignore
if (isLog4NetConfigured) {
// Get the logfile name
try {
if (((Hierarchy)LogManager.GetRepository()).Root.Appenders.Count > 0) {
IAppender appender = ((Hierarchy)LogManager.GetRepository()).Root.Appenders[0];
if (appender is FileAppender) {
return ((FileAppender)appender).File;
}
}
} catch {}
}
return null;
}