added NLog to lib folder for logging

added log configuration to ANX.Framework assembly
added debug logging to ANX.Inputsystem.Windows.XInput and ANX.Framework
This commit is contained in:
Glatzemann 2011-11-21 16:00:02 +00:00
parent dd640f61e2
commit f931832502
8 changed files with 96 additions and 21 deletions

View File

@ -36,6 +36,10 @@
<AllowUnsafeBlocks>true</AllowUnsafeBlocks> <AllowUnsafeBlocks>true</AllowUnsafeBlocks>
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
<Reference Include="NLog, Version=2.0.0.0, Culture=neutral, PublicKeyToken=5120e14c03d0593c, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\lib\NLog\NLog.dll</HintPath>
</Reference>
<Reference Include="System" /> <Reference Include="System" />
<Reference Include="System.Core" /> <Reference Include="System.Core" />
<Reference Include="System.Xml.Linq" /> <Reference Include="System.Xml.Linq" />
@ -459,6 +463,11 @@
<ItemGroup> <ItemGroup>
<Folder Include="Content\MediaTypeReaders\" /> <Folder Include="Content\MediaTypeReaders\" />
</ItemGroup> </ItemGroup>
<ItemGroup>
<None Include="NLog.config">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it. <!-- 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. Other similar extension points exist, see Microsoft.Common.targets.

View File

@ -7,6 +7,7 @@ using System.Threading;
using ANX.Framework.Content; using ANX.Framework.Content;
using ANX.Framework.Graphics; using ANX.Framework.Graphics;
using ANX.Framework.NonXNA; using ANX.Framework.NonXNA;
using NLog;
#endregion // Using Statements #endregion // Using Statements
@ -61,6 +62,8 @@ namespace ANX.Framework
{ {
public class Game : IDisposable public class Game : IDisposable
{ {
private static Logger logger = LogManager.GetCurrentClassLogger();
private IGraphicsDeviceManager graphicsDeviceManager; private IGraphicsDeviceManager graphicsDeviceManager;
private IGraphicsDeviceService graphicsDeviceService; private IGraphicsDeviceService graphicsDeviceService;
private GameServiceContainer gameServices; private GameServiceContainer gameServices;
@ -98,15 +101,22 @@ namespace ANX.Framework
public Game(String renderSystemName = "DirectX10", String inputSystemName = "XInput", String soundSystemName = "XAudio") public Game(String renderSystemName = "DirectX10", String inputSystemName = "XInput", String soundSystemName = "XAudio")
{ {
logger.Info("created a new Game-Class");
logger.Info("- asked for RenderSystem '{0}'", renderSystemName);
logger.Info("- asked for InputSystem '{0}'", inputSystemName);
logger.Info("- asked for SoundSystem '{0}'", soundSystemName);
this.gameServices = new GameServiceContainer(); this.gameServices = new GameServiceContainer();
this.gameTime = new GameTime(); this.gameTime = new GameTime();
try try
{ {
AddInSystemFactory.Instance.Initialize(); logger.Info("initializing AddInSystemFactory");
AddInSystemFactory.Instance.Initialize();
} }
catch (Exception ex) catch (Exception ex)
{ {
logger.ErrorException("Error while initializing AddInSystem.", ex);
throw new AddInLoadingException("Error while initializing AddInSystem.", ex); throw new AddInLoadingException("Error while initializing AddInSystem.", ex);
} }
@ -116,6 +126,7 @@ namespace ANX.Framework
} }
catch (Exception ex) catch (Exception ex)
{ {
logger.ErrorException(String.Format("Error during loading InputSystem {0}", inputSystemName), ex);
throw new AddInLoadingException(String.Format("Error during loading InputSystem {0}", inputSystemName), ex); throw new AddInLoadingException(String.Format("Error during loading InputSystem {0}", inputSystemName), ex);
} }
IInputSystemCreator inputSystemCreator = AddInSystemFactory.Instance.GetDefaultCreator<IInputSystemCreator>(); IInputSystemCreator inputSystemCreator = AddInSystemFactory.Instance.GetDefaultCreator<IInputSystemCreator>();
@ -124,12 +135,14 @@ namespace ANX.Framework
this.gameServices.AddService(typeof(IInputSystemCreator), inputSystemCreator); this.gameServices.AddService(typeof(IInputSystemCreator), inputSystemCreator);
} }
try{ try
AddInSystemFactory.Instance.SetDefaultCreator(soundSystemName); {
AddInSystemFactory.Instance.SetDefaultCreator(soundSystemName);
} }
catch (Exception ex) catch (Exception ex)
{ {
throw new AddInLoadingException(String.Format("Error during loading SoundSystem {0}", inputSystemName), ex); logger.ErrorException(String.Format("Error during loading SoundSystem {0}", soundSystemName), ex);
throw new AddInLoadingException(String.Format("Error during loading SoundSystem {0}", soundSystemName), ex);
} }
ISoundSystemCreator soundSystemCreator = AddInSystemFactory.Instance.GetDefaultCreator<ISoundSystemCreator>(); ISoundSystemCreator soundSystemCreator = AddInSystemFactory.Instance.GetDefaultCreator<ISoundSystemCreator>();
@ -140,11 +153,12 @@ namespace ANX.Framework
try try
{ {
AddInSystemFactory.Instance.SetDefaultCreator(renderSystemName); AddInSystemFactory.Instance.SetDefaultCreator(renderSystemName);
} }
catch (Exception ex) catch (Exception ex)
{ {
throw new AddInLoadingException(String.Format("Error during loading RenderSystem {0}", inputSystemName), ex); logger.ErrorException(String.Format("Error during loading RenderSystem {0}", renderSystemName), ex);
throw new AddInLoadingException(String.Format("Error during loading RenderSystem {0}", renderSystemName), ex);
} }
IRenderSystemCreator renderSystemCreator = AddInSystemFactory.Instance.GetDefaultCreator<IRenderSystemCreator>(); IRenderSystemCreator renderSystemCreator = AddInSystemFactory.Instance.GetDefaultCreator<IRenderSystemCreator>();
if (renderSystemCreator != null) if (renderSystemCreator != null)
@ -152,6 +166,8 @@ namespace ANX.Framework
this.gameServices.AddService(typeof(IRenderSystemCreator), renderSystemCreator); this.gameServices.AddService(typeof(IRenderSystemCreator), renderSystemCreator);
} }
logger.Info("creating GameHost");
//TODO: error handling if creator is null //TODO: error handling if creator is null
this.host = AddInSystemFactory.Instance.GetDefaultCreator<IRenderSystemCreator>().CreateGameHost(this); this.host = AddInSystemFactory.Instance.GetDefaultCreator<IRenderSystemCreator>().CreateGameHost(this);
@ -162,13 +178,17 @@ namespace ANX.Framework
this.host.Idle += new EventHandler<EventArgs>(this.HostIdle); this.host.Idle += new EventHandler<EventArgs>(this.HostIdle);
this.host.Exiting += new EventHandler<EventArgs>(this.HostExiting); this.host.Exiting += new EventHandler<EventArgs>(this.HostExiting);
logger.Info("creating ContentManager");
this.content = new ContentManager(this.gameServices); this.content = new ContentManager(this.gameServices);
logger.Info("creating GameTimer");
this.clock = new GameTimer(); this.clock = new GameTimer();
this.isFixedTimeStep = true; this.isFixedTimeStep = true;
this.gameUpdateTime = new GameTime(); this.gameUpdateTime = new GameTime();
this.inactiveSleepTime = TimeSpan.Zero; this.inactiveSleepTime = TimeSpan.Zero;
this.targetElapsedTime = TimeSpan.FromTicks(TimeSpan.TicksPerSecond / 60L); // default is 1/60s this.targetElapsedTime = TimeSpan.FromTicks(TimeSpan.TicksPerSecond / 60L); // default is 1/60s
logger.Info("finished initializing new Game class");
} }
~Game() ~Game()

15
ANX.Framework/NLog.config Normal file
View File

@ -0,0 +1,15 @@
<?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">
<!-- make sure to set 'Copy To Output Directory' option for this file -->
<!-- go to http://nlog-project.org/wiki/Configuration_file for more information -->
<targets>
<target name="file" xsi:type="File" fileName="${basedir}/log.txt" deleteOldFileOnStartup="true" />
</targets>
<rules>
<logger name="*" minlevel="Debug" writeTo="file" />
</rules>
</nlog>

View File

@ -5,6 +5,7 @@ using System.Reflection;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using ANX.Framework.Input; using ANX.Framework.Input;
using NLog;
#endregion // Using Statements #endregion // Using Statements
@ -64,6 +65,8 @@ namespace ANX.Framework.NonXNA
private bool initialized; private bool initialized;
private Dictionary<Type, ICreator> defaultCreators = new Dictionary<Type, ICreator>(); private Dictionary<Type, ICreator> defaultCreators = new Dictionary<Type, ICreator>();
private static Logger logger = LogManager.GetCurrentClassLogger();
public static AddInSystemFactory Instance public static AddInSystemFactory Instance
{ {
get get
@ -71,6 +74,7 @@ namespace ANX.Framework.NonXNA
if (instance == null) if (instance == null)
{ {
instance = new AddInSystemFactory(); instance = new AddInSystemFactory();
logger.Debug("Created AddInSystemFactory instance");
} }
return instance; return instance;
@ -86,12 +90,16 @@ namespace ANX.Framework.NonXNA
{ {
if (!initialized) if (!initialized)
{ {
logger.Info("[ANX] Initializing ANX.Framework AddInSystemFactory...");
String executingAssembly = Assembly.GetExecutingAssembly().Location; String executingAssembly = Assembly.GetExecutingAssembly().Location;
foreach (String file in Directory.EnumerateFiles(Path.GetDirectoryName(executingAssembly), "*.dll", SearchOption.TopDirectoryOnly)) foreach (String file in Directory.EnumerateFiles(Path.GetDirectoryName(executingAssembly), "*.dll", SearchOption.TopDirectoryOnly))
{ {
if (!file.Equals(executingAssembly)) if (!file.Equals(executingAssembly))
{ {
logger.Info("[ANX] trying to load '{0}'...", file);
Assembly part = null; Assembly part = null;
try try
@ -100,16 +108,20 @@ namespace ANX.Framework.NonXNA
} }
catch (Exception ex) catch (Exception ex)
{ {
logger.Debug("error calling Assembly.LoadFile({0}) Exception: {1}", file, ex.Message);
} }
if (part != null) if (part != null)
{ {
logger.Info("[ANX] scanning for ANX interfaces...");
foreach (Type t in part.GetTypes().Where(p => typeof(IInputSystemCreator).IsAssignableFrom(p) || foreach (Type t in part.GetTypes().Where(p => typeof(IInputSystemCreator).IsAssignableFrom(p) ||
typeof(IRenderSystemCreator).IsAssignableFrom(p) || typeof(IRenderSystemCreator).IsAssignableFrom(p) ||
typeof(ISoundSystemCreator).IsAssignableFrom(p) typeof(ISoundSystemCreator).IsAssignableFrom(p)
)) ))
{ {
logger.Info("[ANX] registering instance of '{0}'...", t.FullName);
var instance = part.CreateInstance(t.FullName); var instance = part.CreateInstance(t.FullName);
((ICreator)instance).RegisterCreator(this); ((ICreator)instance).RegisterCreator(this);
} }

View File

@ -31,8 +31,8 @@ using System.Runtime.InteropServices;
// //
// Sie können alle Werte angeben oder die standardmäßigen Build- und Revisionsnummern // Sie können alle Werte angeben oder die standardmäßigen Build- und Revisionsnummern
// übernehmen, indem Sie "*" eingeben: // übernehmen, indem Sie "*" eingeben:
[assembly: AssemblyVersion("0.4.19.*")] [assembly: AssemblyVersion("0.4.20.*")]
[assembly: AssemblyFileVersion("0.4.19.0")] [assembly: AssemblyFileVersion("0.4.20.0")]
[assembly:InternalsVisibleTo("ANX.Framework.Windows.DX10")] [assembly:InternalsVisibleTo("ANX.Framework.Windows.DX10")]
[assembly:InternalsVisibleTo("ANX.Framework.Windows.DX11.1")] [assembly:InternalsVisibleTo("ANX.Framework.Windows.DX11.1")]

View File

@ -31,6 +31,10 @@
<WarningLevel>4</WarningLevel> <WarningLevel>4</WarningLevel>
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
<Reference Include="NLog, Version=2.0.0.0, Culture=neutral, PublicKeyToken=5120e14c03d0593c, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\lib\NLog\NLog.dll</HintPath>
</Reference>
<Reference Include="SharpDX"> <Reference Include="SharpDX">
<HintPath>..\..\lib\SharpDX\Bin\SharpDX.dll</HintPath> <HintPath>..\..\lib\SharpDX\Bin\SharpDX.dll</HintPath>
</Reference> </Reference>

View File

@ -6,6 +6,7 @@ using System.Text;
using System.IO; using System.IO;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
using ANX.Framework.NonXNA; using ANX.Framework.NonXNA;
using NLog;
#endregion // Using Statements #endregion // Using Statements
@ -60,33 +61,47 @@ namespace ANX.InputSystem.Windows.XInput
{ {
public class Creator : IInputSystemCreator public class Creator : IInputSystemCreator
{ {
private static Logger logger = LogManager.GetCurrentClassLogger();
public string Name public string Name
{ {
get { return "XInput"; } get
} {
return "XInput";
public IGamePad GamePad }
{
get { return new GamePad(); }
} }
public void RegisterCreator(AddInSystemFactory factory) public void RegisterCreator(AddInSystemFactory factory)
{ {
logger.Debug("adding XInput creator to creator collection of AddInSystemFactory");
factory.AddCreator(this); factory.AddCreator(this);
} }
public IGamePad GamePad
{
get
{
logger.Debug("returning a new XInput GamePad device");
return new GamePad();
}
}
public IMouse Mouse public IMouse Mouse
{ {
get { return new Mouse(); } get
{
logger.Debug("returning a new XInput Mouse device");
return new Mouse();
}
} }
public IKeyboard Keyboard public IKeyboard Keyboard
{ {
get { return new Keyboard(); } get
{
logger.Debug("returning a new XInput Keyboard device");
return new Keyboard();
}
} }
#if XNAEXT #if XNAEXT

View File

@ -32,5 +32,5 @@ using System.Runtime.InteropServices;
// Sie können alle Werte angeben oder die standardmäßigen Build- und Revisionsnummern // Sie können alle Werte angeben oder die standardmäßigen Build- und Revisionsnummern
// übernehmen, indem Sie "*" eingeben: // übernehmen, indem Sie "*" eingeben:
// [assembly: AssemblyVersion("1.0.*")] // [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("0.6.0.0")] [assembly: AssemblyVersion("0.6.1.0")]
[assembly: AssemblyFileVersion("0.6.0.0")] [assembly: AssemblyFileVersion("0.6.1.0")]