mirror of
https://github.com/greenshot/greenshot
synced 2025-08-20 13:33:27 -07:00
Fixed log file not being created.
git-svn-id: http://svn.code.sf.net/p/greenshot/code/trunk@2448 7dccd23d-a4a3-4e1f-8c07-b4c1b4018ab4
This commit is contained in:
parent
c9f87937f6
commit
d3b792bb3e
3 changed files with 23 additions and 6 deletions
|
@ -6,7 +6,7 @@
|
|||
<file type="log4net.Util.PatternString">
|
||||
<converter>
|
||||
<name value="folder" />
|
||||
<type value="Greenshot.Helpers.SpecialFolderPatternConverter" />
|
||||
<type value="GreenshotPlugin.Core.SpecialFolderPatternConverter" />
|
||||
</converter>
|
||||
<conversionPattern value="%folder{LocalApplicationData}\Greenshot\Greenshot.log" />
|
||||
</file>
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
<file type="log4net.Util.PatternString">
|
||||
<converter>
|
||||
<name value="folder" />
|
||||
<type value="Greenshot.Helpers.SpecialFolderPatternConverter" />
|
||||
<type value="GreenshotPlugin.Core.SpecialFolderPatternConverter" />
|
||||
</converter>
|
||||
<conversionPattern value="%folder{LocalApplicationData}\Greenshot\Greenshot.log" />
|
||||
</file>
|
||||
|
|
|
@ -27,6 +27,7 @@ using log4net;
|
|||
using log4net.Appender;
|
||||
using log4net.Config;
|
||||
using log4net.Repository.Hierarchy;
|
||||
using System;
|
||||
|
||||
namespace GreenshotPlugin.Core {
|
||||
/// <summary>
|
||||
|
@ -35,7 +36,7 @@ namespace GreenshotPlugin.Core {
|
|||
public class LogHelper {
|
||||
private const string LOG4NET_FILE = "log4net.xml";
|
||||
private static bool isLog4NetConfigured = false;
|
||||
|
||||
private const string INIT_MESSAGE = "Greenshot initialization of log system failed";
|
||||
public static bool isInitialized {
|
||||
get {
|
||||
return isLog4NetConfigured;
|
||||
|
@ -52,12 +53,16 @@ namespace GreenshotPlugin.Core {
|
|||
try {
|
||||
XmlConfigurator.Configure(new FileInfo(log4netFilename));
|
||||
isLog4NetConfigured = true;
|
||||
} catch {}
|
||||
} catch (Exception ex) {
|
||||
MessageBox.Show(ex.Message, INIT_MESSAGE, MessageBoxButtons.OK, MessageBoxIcon.Warning);
|
||||
}
|
||||
} else if (File.Exists(pafLog4NetFilename)) {
|
||||
try {
|
||||
XmlConfigurator.Configure(new FileInfo(pafLog4NetFilename));
|
||||
isLog4NetConfigured = true;
|
||||
} catch { }
|
||||
} catch (Exception ex) {
|
||||
MessageBox.Show(ex.Message, INIT_MESSAGE, MessageBoxButtons.OK, MessageBoxIcon.Warning);
|
||||
}
|
||||
}
|
||||
|
||||
if (!isLog4NetConfigured) {
|
||||
|
@ -68,7 +73,9 @@ namespace GreenshotPlugin.Core {
|
|||
isLog4NetConfigured = true;
|
||||
IniConfig.ForceIniInStartupPath();
|
||||
}
|
||||
} catch {}
|
||||
} catch (Exception ex){
|
||||
MessageBox.Show(ex.Message, INIT_MESSAGE, MessageBoxButtons.OK, MessageBoxIcon.Warning);
|
||||
}
|
||||
}
|
||||
|
||||
if (isLog4NetConfigured) {
|
||||
|
@ -86,4 +93,14 @@ namespace GreenshotPlugin.Core {
|
|||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// A simple helper class to support the logging to the AppData location
|
||||
/// </summary>
|
||||
public class SpecialFolderPatternConverter : log4net.Util.PatternConverter {
|
||||
override protected void Convert(System.IO.TextWriter writer, object state) {
|
||||
Environment.SpecialFolder specialFolder = (Environment.SpecialFolder)Enum.Parse(typeof(Environment.SpecialFolder), base.Option, true);
|
||||
writer.Write(Environment.GetFolderPath(specialFolder));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue