Change log facility.

This commit is contained in:
qianlifeng
2015-01-20 22:33:45 +08:00
parent 3f6cb3cd73
commit 1ef163f827
26 changed files with 2746 additions and 135 deletions

View File

@@ -35,10 +35,6 @@
<Prefer32Bit>false</Prefer32Bit> <Prefer32Bit>false</Prefer32Bit>
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
<Reference Include="log4net, Version=1.2.13.0, Culture=neutral, PublicKeyToken=669e0ddf0bb1aa2a, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\packages\log4net.2.0.3\lib\net35-full\log4net.dll</HintPath>
</Reference>
<Reference Include="Newtonsoft.Json"> <Reference Include="Newtonsoft.Json">
<HintPath>..\..\packages\Newtonsoft.Json.6.0.8\lib\net35\Newtonsoft.Json.dll</HintPath> <HintPath>..\..\packages\Newtonsoft.Json.6.0.8\lib\net35\Newtonsoft.Json.dll</HintPath>
<Private>True</Private> <Private>True</Private>

View File

@@ -1,6 +1,5 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<packages> <packages>
<package id="log4net" version="2.0.3" targetFramework="net35" />
<package id="Newtonsoft.Json" version="6.0.8" targetFramework="net35" /> <package id="Newtonsoft.Json" version="6.0.8" targetFramework="net35" />
<package id="WindowsInput" version="0.2.0.0" targetFramework="net35" /> <package id="WindowsInput" version="0.2.0.0" targetFramework="net35" />
</packages> </packages>

View File

@@ -35,10 +35,6 @@
<Prefer32Bit>false</Prefer32Bit> <Prefer32Bit>false</Prefer32Bit>
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
<Reference Include="log4net, Version=1.2.13.0, Culture=neutral, PublicKeyToken=669e0ddf0bb1aa2a, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\packages\log4net.2.0.3\lib\net35-full\log4net.dll</HintPath>
</Reference>
<Reference Include="Newtonsoft.Json"> <Reference Include="Newtonsoft.Json">
<HintPath>..\..\packages\Newtonsoft.Json.6.0.8\lib\net35\Newtonsoft.Json.dll</HintPath> <HintPath>..\..\packages\Newtonsoft.Json.6.0.8\lib\net35\Newtonsoft.Json.dll</HintPath>
<Private>True</Private> <Private>True</Private>

View File

@@ -1,5 +1,4 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<packages> <packages>
<package id="log4net" version="2.0.3" targetFramework="net35" />
<package id="Newtonsoft.Json" version="6.0.8" targetFramework="net35" /> <package id="Newtonsoft.Json" version="6.0.8" targetFramework="net35" />
</packages> </packages>

View File

@@ -35,10 +35,6 @@
<Prefer32Bit>false</Prefer32Bit> <Prefer32Bit>false</Prefer32Bit>
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
<Reference Include="log4net">
<HintPath>..\..\packages\log4net.2.0.3\lib\net35-full\log4net.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="Newtonsoft.Json, Version=6.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL"> <Reference Include="Newtonsoft.Json, Version=6.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion> <SpecificVersion>False</SpecificVersion>
<HintPath>..\..\packages\Newtonsoft.Json.6.0.8\lib\net35\Newtonsoft.Json.dll</HintPath> <HintPath>..\..\packages\Newtonsoft.Json.6.0.8\lib\net35\Newtonsoft.Json.dll</HintPath>

View File

@@ -1,5 +1,4 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<packages> <packages>
<package id="log4net" version="2.0.3" targetFramework="net35" />
<package id="Newtonsoft.Json" version="6.0.8" targetFramework="net35" /> <package id="Newtonsoft.Json" version="6.0.8" targetFramework="net35" />
</packages> </packages>

View File

@@ -35,10 +35,6 @@
<Prefer32Bit>false</Prefer32Bit> <Prefer32Bit>false</Prefer32Bit>
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
<Reference Include="log4net, Version=1.2.13.0, Culture=neutral, PublicKeyToken=669e0ddf0bb1aa2a, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\packages\log4net.2.0.3\lib\net35-full\log4net.dll</HintPath>
</Reference>
<Reference Include="PresentationCore" /> <Reference Include="PresentationCore" />
<Reference Include="PresentationFramework" /> <Reference Include="PresentationFramework" />
<Reference Include="System" /> <Reference Include="System" />
@@ -90,7 +86,6 @@
</Page> </Page>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<None Include="packages.config" />
<None Include="plugin.json"> <None Include="plugin.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None> </None>

View File

@@ -1,4 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="log4net" version="2.0.3" targetFramework="net35" />
</packages>

View File

@@ -35,10 +35,6 @@
<Prefer32Bit>false</Prefer32Bit> <Prefer32Bit>false</Prefer32Bit>
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
<Reference Include="log4net, Version=1.2.13.0, Culture=neutral, PublicKeyToken=669e0ddf0bb1aa2a, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\packages\log4net.2.0.3\lib\net35-full\log4net.dll</HintPath>
</Reference>
<Reference Include="Newtonsoft.Json, Version=6.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL"> <Reference Include="Newtonsoft.Json, Version=6.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion> <SpecificVersion>False</SpecificVersion>
<HintPath>..\..\packages\Newtonsoft.Json.6.0.8\lib\net35\Newtonsoft.Json.dll</HintPath> <HintPath>..\..\packages\Newtonsoft.Json.6.0.8\lib\net35\Newtonsoft.Json.dll</HintPath>

View File

@@ -1,5 +1,4 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<packages> <packages>
<package id="log4net" version="2.0.3" targetFramework="net35" />
<package id="Newtonsoft.Json" version="6.0.8" targetFramework="net35" /> <package id="Newtonsoft.Json" version="6.0.8" targetFramework="net35" />
</packages> </packages>

View File

@@ -37,7 +37,7 @@ namespace Wox.Core.Plugin
return; return;
} }
string pluginFolerPath = PluginManager.DefaultPluginDirectory; string pluginFolerPath = PluginManager.PluginDirectory;
string newPluginName = plugin.Name string newPluginName = plugin.Name
.Replace("/", "_") .Replace("/", "_")

View File

@@ -30,35 +30,17 @@ namespace Wox.Core.Plugin
private static List<string> pluginDirectories = new List<string>(); private static List<string> pluginDirectories = new List<string>();
/// <summary>
/// Default plugin directory
/// new plugin will be installed to this directory
/// </summary>
public static string DefaultPluginDirectory
{
get
{
string userProfilePath = Environment.GetEnvironmentVariable("USERPROFILE");
if (string.IsNullOrEmpty(userProfilePath))
{
throw new WoxCritialException("Wox Can't Find Environment Variable UserProfile");
}
return Path.Combine(Path.Combine(userProfilePath, ".Wox"), "Plugins");
}
}
private static void SetupPluginDirectories() private static void SetupPluginDirectories()
{ {
pluginDirectories.Clear(); pluginDirectories.Add(PluginDirectory);
pluginDirectories.Add(DefaultPluginDirectory);
pluginDirectories.Add(
Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "Plugins"));
MakesurePluginDirectoriesExist(); MakesurePluginDirectoriesExist();
} }
public static string PluginDirectory
{
get { return Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "Plugins"); }
}
private static void MakesurePluginDirectoriesExist() private static void MakesurePluginDirectoriesExist()
{ {
foreach (string pluginDirectory in pluginDirectories) foreach (string pluginDirectory in pluginDirectories)

View File

@@ -19,13 +19,6 @@ namespace Wox.Core.Theme
static Theme() static Theme()
{ {
themeDirectories.Add(Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "Themes")); themeDirectories.Add(Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "Themes"));
string userProfilePath = Environment.GetEnvironmentVariable("USERPROFILE");
if (userProfilePath != null)
{
themeDirectories.Add(Path.Combine(Path.Combine(userProfilePath, ".Wox"), "Themes"));
}
MakesureThemeDirectoriesExist(); MakesureThemeDirectoriesExist();
} }

View File

@@ -35,10 +35,6 @@
<Prefer32Bit>false</Prefer32Bit> <Prefer32Bit>false</Prefer32Bit>
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
<Reference Include="log4net, Version=1.2.13.0, Culture=neutral, PublicKeyToken=669e0ddf0bb1aa2a, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\packages\log4net.2.0.3\lib\net35-full\log4net.dll</HintPath>
</Reference>
<Reference Include="PresentationCore" /> <Reference Include="PresentationCore" />
<Reference Include="PresentationFramework" /> <Reference Include="PresentationFramework" />
<Reference Include="System" /> <Reference Include="System" />
@@ -95,9 +91,6 @@
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Resource> </Resource>
</ItemGroup> </ItemGroup>
<ItemGroup>
<None Include="packages.config" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<Import Project="$(SolutionDir)\.nuget\NuGet.targets" Condition="Exists('$(SolutionDir)\.nuget\NuGet.targets')" /> <Import Project="$(SolutionDir)\.nuget\NuGet.targets" Condition="Exists('$(SolutionDir)\.nuget\NuGet.targets')" />
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild"> <Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">

View File

@@ -1,4 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="log4net" version="2.0.3" targetFramework="net35" />
</packages>

View File

@@ -1,41 +1,41 @@
using System; using System;
using System.Reflection; using System.Reflection;
using log4net; using NLog;
namespace Wox.Infrastructure.Logger namespace Wox.Infrastructure.Logger
{ {
public class Log public class Log
{ {
private static ILog fileLogger = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); private static NLog.Logger logger = LogManager.GetCurrentClassLogger();
public static void Error(string msg) public static void Error(string msg)
{ {
fileLogger.Error(msg); logger.Error(msg);
} }
public static void Error(Exception e) public static void Error(Exception e)
{ {
fileLogger.Error(e.Message + "\r\n" + e.StackTrace); logger.Error(e.Message + "\r\n" + e.StackTrace);
} }
public static void Debug(string msg) public static void Debug(string msg)
{ {
fileLogger.Debug(msg); logger.Debug(msg);
} }
public static void Info(string msg) public static void Info(string msg)
{ {
fileLogger.Info(msg); logger.Info(msg);
} }
public static void Warn(string msg) public static void Warn(string msg)
{ {
fileLogger.Warn(msg); logger.Warn(msg);
} }
public static void Fatal(string msg) public static void Fatal(string msg)
{ {
fileLogger.Fatal(msg); logger.Fatal(msg);
} }
} }
} }

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,25 @@
<?xml version="1.0" encoding="utf-8" ?>
<nlog xmlns="http://www.nlog-project.org/schemas/NLog.xsd"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<!--
See https://github.com/nlog/nlog/wiki/Configuration-file
for information on customizing logging rules and outputs.
You can use http://www.legitlog.com/ to visualize those logs
-->
<!-- log level
Trace - very detailed logs, which may include high-volume information such as protocol payloads. This log level is typically only enabled during development
Debug - debugging information, less detailed than trace, typically not enabled in production environment.
Info - information messages, which are normally enabled in production environment
Warn - warning messages, typically for non-critical issues, which can be recovered or which are temporary failures
Error - error messages
Fatal - very serious errors-->
<targets>
<target xsi:type="File" name="file" fileName="${basedir}/logs/${shortdate}.log"/>
<target xsi:type="Console" name="console" />
</targets>
<rules>
<logger name="*" minlevel="Warn" writeTo="file" />
<logger name="*" minlevel="Debug" writeTo="console" />
</rules>
</nlog>

View File

@@ -33,5 +33,4 @@ using System.Runtime.InteropServices;
// 方法是按如下所示使用“*”: // 方法是按如下所示使用“*”:
// [assembly: AssemblyVersion("1.0.*")] // [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")] [assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")] [assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: log4net.Config.XmlConfigurator(Watch = true)]

View File

@@ -37,15 +37,14 @@
<Prefer32Bit>false</Prefer32Bit> <Prefer32Bit>false</Prefer32Bit>
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
<Reference Include="log4net">
<HintPath>..\packages\log4net.2.0.3\lib\net35-full\log4net.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="Microsoft.VisualBasic" /> <Reference Include="Microsoft.VisualBasic" />
<Reference Include="Newtonsoft.Json, Version=6.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL"> <Reference Include="Newtonsoft.Json, Version=6.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion> <SpecificVersion>False</SpecificVersion>
<HintPath>..\packages\Newtonsoft.Json.6.0.8\lib\net35\Newtonsoft.Json.dll</HintPath> <HintPath>..\packages\Newtonsoft.Json.6.0.8\lib\net35\Newtonsoft.Json.dll</HintPath>
</Reference> </Reference>
<Reference Include="NLog">
<HintPath>..\packages\NLog.3.2.0.0\lib\net35\NLog.dll</HintPath>
</Reference>
<Reference Include="PresentationCore" /> <Reference Include="PresentationCore" />
<Reference Include="PresentationFramework" /> <Reference Include="PresentationFramework" />
<Reference Include="System" /> <Reference Include="System" />
@@ -84,6 +83,12 @@
</ProjectReference> </ProjectReference>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<Content Include="NLog.config">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
<None Include="Logger\NLog.xsd">
<SubType>Designer</SubType>
</None>
<None Include="packages.config" /> <None Include="packages.config" />
</ItemGroup> </ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />

View File

@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<packages> <packages>
<package id="log4net" version="2.0.3" targetFramework="net35" />
<package id="Newtonsoft.Json" version="6.0.8" targetFramework="net35" /> <package id="Newtonsoft.Json" version="6.0.8" targetFramework="net35" />
<package id="NLog" version="3.2.0.0" targetFramework="net35" />
</packages> </packages>

View File

@@ -1,30 +1,5 @@
<?xml version="1.0"?> <?xml version="1.0"?>
<configuration> <configuration>
<configSections>
<section name="log4net" type="System.Configuration.IgnoreSectionHandler"/>
</configSections>
<log4net>
<appender name="LogFileAppender" type="log4net.Appender.FileAppender">
<file type="log4net.Util.PatternString">
<converter>
<name value="WoxLogPathConverter"/>
<type value="Wox.Helper.WoxLogPathConverter,Wox"/>
</converter>
<conversionPattern value="%WoxLogPathConverter{log}\\log.txt"/>
</file>
<appendToFile value="true"/>
<rollingStyle value="Date"/>
<datePattern value="yyyyMMdd-HH:mm:ss"/>
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="Date%date Level%-5level Msg%message%newline"/>
</layout>
</appender>
<root>
<!-- ALL < DEBUG < INFO < WARN < ERROR < FATAL < OFF-->
<level value="WARN"/>
<appender-ref ref="LogFileAppender"/>
</root>
</log4net>
<runtime> <runtime>
<!--http://stackoverflow.com/questions/186854/how-to-prevent-an-exception-in-a-background-thread-from-terminating-an-application--> <!--http://stackoverflow.com/questions/186854/how-to-prevent-an-exception-in-a-background-thread-from-terminating-an-application-->
<!--prevent non-ui exception crash wox--> <!--prevent non-ui exception crash wox-->

View File

@@ -1,17 +0,0 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
namespace Wox.Helper
{
public class WoxLogPathConverter : log4net.Util.PatternConverter
{
protected override void Convert(TextWriter writer, object state)
{
string userProfilePath = Environment.GetEnvironmentVariable("USERPROFILE");
writer.Write(Path.Combine(userProfilePath, ".Wox"));
}
}
}

View File

@@ -34,6 +34,7 @@ using KeyEventArgs = System.Windows.Input.KeyEventArgs;
using MenuItem = System.Windows.Forms.MenuItem; using MenuItem = System.Windows.Forms.MenuItem;
using MessageBox = System.Windows.MessageBox; using MessageBox = System.Windows.MessageBox;
using ToolTip = System.Windows.Controls.ToolTip; using ToolTip = System.Windows.Controls.ToolTip;
using Wox.Infrastructure.Logger;
namespace Wox namespace Wox
{ {

View File

@@ -66,10 +66,6 @@
<SpecificVersion>False</SpecificVersion> <SpecificVersion>False</SpecificVersion>
<HintPath>..\packages\SharpZipLib.0.86.0\lib\20\ICSharpCode.SharpZipLib.dll</HintPath> <HintPath>..\packages\SharpZipLib.0.86.0\lib\20\ICSharpCode.SharpZipLib.dll</HintPath>
</Reference> </Reference>
<Reference Include="log4net, Version=1.2.13.0, Culture=neutral, PublicKeyToken=669e0ddf0bb1aa2a, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\packages\log4net.2.0.3\lib\net35-full\log4net.dll</HintPath>
</Reference>
<Reference Include="Newtonsoft.Json, Version=6.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL"> <Reference Include="Newtonsoft.Json, Version=6.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion> <SpecificVersion>False</SpecificVersion>
<HintPath>..\packages\Newtonsoft.Json.6.0.8\lib\net35\Newtonsoft.Json.dll</HintPath> <HintPath>..\packages\Newtonsoft.Json.6.0.8\lib\net35\Newtonsoft.Json.dll</HintPath>
@@ -115,7 +111,6 @@
<Compile Include="Converters\OpacityModeConverter.cs" /> <Compile Include="Converters\OpacityModeConverter.cs" />
<Compile Include="Converters\StringEmptyConverter.cs" /> <Compile Include="Converters\StringEmptyConverter.cs" />
<Compile Include="Converters\StringNullOrEmptyToVisibilityConverter.cs" /> <Compile Include="Converters\StringNullOrEmptyToVisibilityConverter.cs" />
<Compile Include="Helper\WoxLogPathConverter.cs" />
<Compile Include="ImageLoader\ImageCacheStroage.cs" /> <Compile Include="ImageLoader\ImageCacheStroage.cs" />
<Compile Include="Storage\UserSelectedRecordStorage.cs" /> <Compile Include="Storage\UserSelectedRecordStorage.cs" />
<Compile Include="Update\NewVersionWindow.xaml.cs"> <Compile Include="Update\NewVersionWindow.xaml.cs">

View File

@@ -1,7 +1,6 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<packages> <packages>
<package id="InputSimulator" version="1.0.4.0" targetFramework="net35" /> <package id="InputSimulator" version="1.0.4.0" targetFramework="net35" />
<package id="log4net" version="2.0.3" targetFramework="net35" />
<package id="Newtonsoft.Json" version="6.0.8" targetFramework="net35" /> <package id="Newtonsoft.Json" version="6.0.8" targetFramework="net35" />
<package id="NHotkey" version="1.2.1" targetFramework="net35" /> <package id="NHotkey" version="1.2.1" targetFramework="net35" />
<package id="NHotkey.Wpf" version="1.2.1" targetFramework="net35" /> <package id="NHotkey.Wpf" version="1.2.1" targetFramework="net35" />