فهرست منبع

增加NLog日志库

tanghai 14 سال پیش
والد
کامیت
9348e68c0a

+ 1 - 0
.gitignore

@@ -15,4 +15,5 @@ Opt/
 bin/
 obj/
 Properties/
+packages/
 

+ 8 - 0
CSharp/Editor/App.xaml.cs

@@ -1,6 +1,7 @@
 using System.Threading.Tasks.Schedulers;
 using System.Windows;
 using GalaSoft.MvvmLight.Threading;
+using NLog;
 
 namespace Egametang
 {
@@ -13,6 +14,7 @@ namespace Egametang
 		{
 			DispatcherHelper.Initialize();
 			OrderedTaskScheduler = new OrderedTaskScheduler();
+			Logger = LogManager.GetLogger("Editor");
 		}
 
 		public static OrderedTaskScheduler OrderedTaskScheduler
@@ -20,5 +22,11 @@ namespace Egametang
 			get;
 			private set;
 		}
+
+		public static Logger Logger
+		{
+			get;
+			private set;
+		}
 	}
 }

+ 15 - 0
CSharp/Editor/Editor.csproj

@@ -47,6 +47,12 @@
       <SpecificVersion>False</SpecificVersion>
       <HintPath>C:\Program Files\Laurent Bugnion (GalaSoft)\Mvvm Light Toolkit\Binaries\WPF4\Microsoft.Practices.ServiceLocation.dll</HintPath>
     </Reference>
+    <Reference Include="NLog">
+      <HintPath>..\packages\NLog.2.0.0.0\lib\NET40\NLog.dll</HintPath>
+    </Reference>
+    <Reference Include="NLog.Extended">
+      <HintPath>..\packages\NLog.2.0.0.0\lib\NET40\NLog.Extended.dll</HintPath>
+    </Reference>
     <Reference Include="System.Windows.Interactivity">
       <SpecificVersion>False</SpecificVersion>
       <HintPath>C:\Program Files\Laurent Bugnion (GalaSoft)\Mvvm Light Toolkit\Binaries\WPF4\System.Windows.Interactivity.dll</HintPath>
@@ -72,6 +78,10 @@
     </ApplicationDefinition>
     <Compile Include="Model\DataService.cs" />
     <Compile Include="Model\IDataService.cs" />
+    <None Include="NLog.config">
+      <SubType>Designer</SubType>
+      <CopyToOutputDirectory>Always</CopyToOutputDirectory>
+    </None>
     <Compile Include="ViewModel\MainViewModel.cs" />
     <Compile Include="ViewModel\ViewModelLocator.cs" />
     <Compile Include="View\MainView.xaml.cs">
@@ -106,6 +116,11 @@
       <Name>Thread</Name>
     </ProjectReference>
   </ItemGroup>
+  <ItemGroup>
+    <None Include="Packages.config">
+      <SubType>Designer</SubType>
+    </None>
+  </ItemGroup>
   <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.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.

+ 11 - 0
CSharp/Editor/NLog.config

@@ -0,0 +1,11 @@
+<?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">
+	<targets>
+		<target name="file" xsi:type="File" fileName="${basedir}/Log.txt"
+				layout="${date:format=HH\:mm\:ss}|${threadid}|${level}|${message}"/>
+	</targets>
+	<rules>
+		<logger name="*" minlevel="Trace" writeTo="file"/>
+	</rules>
+</nlog>

+ 4 - 0
CSharp/Editor/Packages.config

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

+ 3 - 3
CSharp/Editor/ViewModel/MainViewModel.cs

@@ -45,7 +45,7 @@ namespace Egametang
 		{
 			var task = new Task(() =>
 			{
-
+				App.Logger.Debug("11111");
 			});
 			task.ContinueWith(_ =>
 			{
@@ -54,8 +54,8 @@ namespace Egametang
 					{
 						LoginResult = "Login OK!";
 					}));
-			}, App.OrderedTaskScheduler);
-			task.Start();
+			});
+			task.Start(App.OrderedTaskScheduler);
 		}
 
 		public override void Cleanup()

+ 3 - 1
CSharp/Thread/Thread.csproj

@@ -42,7 +42,9 @@
   <ItemGroup>
     <Compile Include="LimitedConcurrencyLevelTaskScheduler.cs" />
     <Compile Include="OrderedTaskScheduler.cs" />
-    <Compile Include="Properties\AssemblyInfo.cs" />
+  </ItemGroup>
+  <ItemGroup>
+    <Folder Include="Properties\" />
   </ItemGroup>
   <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
   <!-- To modify your build process, add your task inside one of the targets below and uncomment it.