Browse Source

增加Log接口,减少对NLog的依赖,以后可以随时替换成任何Log库

tanghai 13 years ago
parent
commit
5a86694ff1

+ 0 - 1
.gitignore

@@ -13,7 +13,6 @@ Opt/
 
 bin/
 obj/
-Properties/
 Packages/
 packages/
 _ReSharper.CSharp/

+ 4 - 3
CSharp/App/Modules/BehaviorTree/BehaviorTree.csproj

@@ -44,9 +44,6 @@
     <Reference Include="Microsoft.Practices.Prism.MefExtensions">
       <HintPath>..\..\..\packages\Prism.MEFExtensions.4.1.0.0\lib\NET40\Microsoft.Practices.Prism.MefExtensions.dll</HintPath>
     </Reference>
-    <Reference Include="NLog">
-      <HintPath>..\..\..\packages\NLog.2.0.0.2000\lib\net40\NLog.dll</HintPath>
-    </Reference>
     <Reference Include="PresentationCore" />
     <Reference Include="PresentationFramework" />
     <Reference Include="System" />
@@ -79,6 +76,10 @@
     </Page>
   </ItemGroup>
   <ItemGroup>
+    <ProjectReference Include="..\..\..\Platform\ELog\ELog.csproj">
+      <Project>{72e16572-fc1f-4a9e-bc96-035417239298}</Project>
+      <Name>ELog</Name>
+    </ProjectReference>
     <ProjectReference Include="..\..\..\Platform\Infrastructure\Infrastructure.csproj">
       <Project>{48A2E149-0DAC-41B4-BB54-DFBCCD6D42B3}</Project>
       <Name>Infrastructure</Name>

+ 2 - 3
CSharp/App/Modules/BehaviorTree/BehaviorTreeLayout.cs

@@ -1,4 +1,4 @@
-using NLog;
+using ELog;
 
 namespace Modules.BehaviorTree
 {
@@ -10,7 +10,6 @@ namespace Modules.BehaviorTree
 		private static double rootOrigY;
 		private static double rootOffsetX;
 		private static double rootOffsetY;
-		private static readonly Logger logger = LogManager.GetCurrentClassLogger();
 
 		private static TreeNodeViewModel LeftMostOffspring(TreeNodeViewModel treeNode, int currentLevel, int searchLevel)
 		{
@@ -127,7 +126,7 @@ namespace Modules.BehaviorTree
 			treeNode.Prelim = prelim;
 			treeNode.Modify = modify;
 
-			logger.Debug("Num: " + treeNode.Num + " Prelim: " + treeNode.Prelim + " Modify: " + treeNode.Modify);
+			Log.Debug("Num: " + treeNode.Num + " Prelim: " + treeNode.Prelim + " Modify: " + treeNode.Modify);
 		}
 
 		private static void CalculateRelativeXAndY(TreeNodeViewModel treeNode, int level, double totalModify)

+ 0 - 1
CSharp/App/Modules/BehaviorTree/Packages.config

@@ -1,7 +1,6 @@
 <?xml version="1.0" encoding="utf-8"?>
 <packages>
   <package id="CommonServiceLocator" version="1.0" targetFramework="net40" />
-  <package id="NLog" version="2.0.0.2000" targetFramework="net40" />
   <package id="Prism" version="4.1.0.0" targetFramework="net40" />
   <package id="Prism.MEFExtensions" version="4.1.0.0" targetFramework="net40" />
 </packages>

+ 0 - 15
CSharp/App/Modules/Robot/Robot.csproj

@@ -32,32 +32,17 @@
     <WarningLevel>4</WarningLevel>
   </PropertyGroup>
   <ItemGroup>
-    <Reference Include="Microsoft.Expression.Interactions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
-      <HintPath>..\..\..\packages\Prism.4.1.0.0\lib\NET40\Microsoft.Expression.Interactions.dll</HintPath>
-    </Reference>
     <Reference Include="Microsoft.Practices.Prism">
       <HintPath>..\..\..\packages\Prism.4.1.0.0\lib\NET40\Microsoft.Practices.Prism.dll</HintPath>
     </Reference>
-    <Reference Include="Microsoft.Practices.Prism.Interactivity">
-      <HintPath>..\..\..\packages\Prism.4.1.0.0\lib\NET40\Microsoft.Practices.Prism.Interactivity.dll</HintPath>
-    </Reference>
     <Reference Include="Microsoft.Practices.Prism.MefExtensions">
       <HintPath>..\..\..\packages\Prism.MEFExtensions.4.1.0.0\lib\NET40\Microsoft.Practices.Prism.MefExtensions.dll</HintPath>
     </Reference>
-    <Reference Include="Microsoft.Practices.ServiceLocation">
-      <HintPath>..\..\..\packages\CommonServiceLocator.1.0\lib\NET35\Microsoft.Practices.ServiceLocation.dll</HintPath>
-    </Reference>
-    <Reference Include="NLog">
-      <HintPath>..\..\..\packages\NLog.2.0.0.2000\lib\net40\NLog.dll</HintPath>
-    </Reference>
     <Reference Include="PresentationCore" />
     <Reference Include="PresentationFramework" />
     <Reference Include="System" />
     <Reference Include="System.ComponentModel.Composition" />
     <Reference Include="System.Core" />
-    <Reference Include="System.Windows.Interactivity, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
-      <HintPath>..\..\..\packages\Prism.4.1.0.0\lib\NET40\System.Windows.Interactivity.dll</HintPath>
-    </Reference>
     <Reference Include="System.Xaml" />
     <Reference Include="System.Xml" />
     <Reference Include="WindowsBase" />

+ 0 - 2
CSharp/App/Modules/Robot/RobotViewModel.cs

@@ -1,14 +1,12 @@
 using System;
 using System.ComponentModel.Composition;
 using Microsoft.Practices.Prism.ViewModel;
-using NLog;
 
 namespace Modules.Robot
 {
 	[Export(contractType: typeof (RobotViewModel)), PartCreationPolicy(creationPolicy: CreationPolicy.NonShared)]
 	internal class RobotViewModel : NotificationObject
 	{
-		private static readonly Logger logger = LogManager.GetCurrentClassLogger();
 		private string logText = "";
 
 		public string LogText

+ 13 - 0
CSharp/CSharp.sln

@@ -26,6 +26,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Enet", "ThirdParty\Enet\Ene
 EndProject
 Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Robot", "App\Modules\Robot\Robot.csproj", "{5D6ECBCD-BE14-4DCB-BAEC-57089748B164}"
 EndProject
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ELog", "Platform\ELog\ELog.csproj", "{72E16572-FC1F-4A9E-BC96-035417239298}"
+EndProject
 Global
 	GlobalSection(SolutionConfigurationPlatforms) = preSolution
 		Debug|Any CPU = Debug|Any CPU
@@ -86,6 +88,16 @@ Global
 		{5D6ECBCD-BE14-4DCB-BAEC-57089748B164}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU
 		{5D6ECBCD-BE14-4DCB-BAEC-57089748B164}.Release|Mixed Platforms.Build.0 = Release|Any CPU
 		{5D6ECBCD-BE14-4DCB-BAEC-57089748B164}.Release|x86.ActiveCfg = Release|Any CPU
+		{72E16572-FC1F-4A9E-BC96-035417239298}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+		{72E16572-FC1F-4A9E-BC96-035417239298}.Debug|Any CPU.Build.0 = Debug|Any CPU
+		{72E16572-FC1F-4A9E-BC96-035417239298}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU
+		{72E16572-FC1F-4A9E-BC96-035417239298}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU
+		{72E16572-FC1F-4A9E-BC96-035417239298}.Debug|x86.ActiveCfg = Debug|Any CPU
+		{72E16572-FC1F-4A9E-BC96-035417239298}.Release|Any CPU.ActiveCfg = Release|Any CPU
+		{72E16572-FC1F-4A9E-BC96-035417239298}.Release|Any CPU.Build.0 = Release|Any CPU
+		{72E16572-FC1F-4A9E-BC96-035417239298}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU
+		{72E16572-FC1F-4A9E-BC96-035417239298}.Release|Mixed Platforms.Build.0 = Release|Any CPU
+		{72E16572-FC1F-4A9E-BC96-035417239298}.Release|x86.ActiveCfg = Release|Any CPU
 	EndGlobalSection
 	GlobalSection(SolutionProperties) = preSolution
 		HideSolutionNode = FALSE
@@ -94,6 +106,7 @@ Global
 		{C4C64188-4FAE-4CC3-A9E6-D9D4AF7429B6} = {6E9D97F0-4243-452E-B832-1A855B8118EB}
 		{C46F3337-0F48-4A72-84AD-8FDD1F159BB0} = {6E9D97F0-4243-452E-B832-1A855B8118EB}
 		{48A2E149-0DAC-41B4-BB54-DFBCCD6D42B3} = {ADBF5F67-B480-4A93-9D50-C81856FC61A9}
+		{72E16572-FC1F-4A9E-BC96-035417239298} = {ADBF5F67-B480-4A93-9D50-C81856FC61A9}
 		{6CD185D1-08E0-4729-A999-2D5B57BA8193} = {C4C64188-4FAE-4CC3-A9E6-D9D4AF7429B6}
 		{5D6ECBCD-BE14-4DCB-BAEC-57089748B164} = {C4C64188-4FAE-4CC3-A9E6-D9D4AF7429B6}
 		{D0B4CFAC-A368-4742-9863-68776CFA9938} = {9173C593-D63F-49F6-AFA7-028425D13E4B}

+ 66 - 0
CSharp/Platform/ELog/ELog.csproj

@@ -0,0 +1,66 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+  <Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
+  <PropertyGroup>
+    <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+    <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+    <ProjectGuid>{72E16572-FC1F-4A9E-BC96-035417239298}</ProjectGuid>
+    <OutputType>Library</OutputType>
+    <AppDesignerFolder>Properties</AppDesignerFolder>
+    <RootNamespace>ELog</RootNamespace>
+    <AssemblyName>ELog</AssemblyName>
+    <TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
+    <FileAlignment>512</FileAlignment>
+    <SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\</SolutionDir>
+    <RestorePackages>true</RestorePackages>
+  </PropertyGroup>
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+    <DebugSymbols>true</DebugSymbols>
+    <DebugType>full</DebugType>
+    <Optimize>false</Optimize>
+    <OutputPath>bin\Debug\</OutputPath>
+    <DefineConstants>DEBUG;TRACE</DefineConstants>
+    <ErrorReport>prompt</ErrorReport>
+    <WarningLevel>4</WarningLevel>
+  </PropertyGroup>
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+    <DebugType>pdbonly</DebugType>
+    <Optimize>true</Optimize>
+    <OutputPath>bin\Release\</OutputPath>
+    <DefineConstants>TRACE</DefineConstants>
+    <ErrorReport>prompt</ErrorReport>
+    <WarningLevel>4</WarningLevel>
+  </PropertyGroup>
+  <ItemGroup>
+    <Reference Include="NLog">
+      <HintPath>..\..\packages\NLog.2.0.0.2000\lib\net40\NLog.dll</HintPath>
+    </Reference>
+    <Reference Include="System" />
+    <Reference Include="System.Core" />
+    <Reference Include="System.Xml.Linq" />
+    <Reference Include="System.Data.DataSetExtensions" />
+    <Reference Include="Microsoft.CSharp" />
+    <Reference Include="System.Data" />
+    <Reference Include="System.Xml" />
+  </ItemGroup>
+  <ItemGroup>
+    <Compile Include="Log.cs" />
+    <Compile Include="ILog.cs" />
+    <Compile Include="NLog.cs" />
+  </ItemGroup>
+  <ItemGroup>
+    <None Include="Packages.config" />
+  </ItemGroup>
+  <ItemGroup>
+    <Folder Include="Properties\" />
+  </ItemGroup>
+  <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
+  <Import Project="$(SolutionDir)\.nuget\nuget.targets" />
+  <!-- To modify your build process, add your task inside one of the targets below and uncomment it. 
+       Other similar extension points exist, see Microsoft.Common.targets.
+  <Target Name="BeforeBuild">
+  </Target>
+  <Target Name="AfterBuild">
+  </Target>
+  -->
+</Project>

+ 8 - 0
CSharp/Platform/ELog/ILog.cs

@@ -0,0 +1,8 @@
+
+namespace ELog
+{
+    public interface ILog
+    {
+	    void Debug(string message);
+    }
+}

+ 13 - 0
CSharp/Platform/ELog/Log.cs

@@ -0,0 +1,13 @@
+
+namespace ELog
+{
+	public static class Log
+	{
+		private static readonly ILog logger = new NLog();
+
+		public static void Debug(string message)
+		{
+			logger.Debug(message);
+		}
+	}
+}

+ 14 - 0
CSharp/Platform/ELog/NLog.cs

@@ -0,0 +1,14 @@
+using NLog;
+
+namespace ELog
+{
+	public class NLog: ILog
+	{
+		private readonly Logger logger = LogManager.GetCurrentClassLogger();
+
+		public void Debug(string message)
+		{
+			logger.Debug(message);
+		}
+	}
+}

+ 4 - 0
CSharp/Platform/ELog/Packages.config

@@ -0,0 +1,4 @@
+<?xml version="1.0" encoding="utf-8"?>
+<packages>
+  <package id="NLog" version="2.0.0.2000" targetFramework="net45" />
+</packages>