NLog with Xamarin cross-plattform application doesn't log anything - android

I set up NLog like this in the Android part of my Xamarin-project.
My NLog.config looks like this:
<?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"
xsi:schemaLocation="http://www.nlog-project.org/schemas/NLog.xsd NLog.xsd"
autoReload="true"
throwExceptions="true"
throwConfigExceptions="true"
internalLogLevel ="Trace"
internalLogFile ="C:\Users\MyUser\intLogFile.txt"
internalLogToConsole="true"
internalLogIncludeTimestamp ="true">
<targets>
<target name="file" xsi:type="File"
layout="${longdate} ${logger} ${message}${exception:format=ToString}"
fileName="/storage/emulated/0/Download/${shortdate}.log" />
</targets>
<rules>
<logger name="*" minlevel="Debug" writeTo="file" />
</rules>
</nlog>
I put the NLog.config in the assets-folder in my android-project.
I added this NuGet to my android-project.
I changed the build action to embedded resource.
I made sure to have writing permissions on the external storage of the device.
I am loading the NLog configuration programmatically like this and nlogConfigFile != null is true so I assume the NLog.config is found.
As you can see I enabled throwing exceptions from NLog but there are no exceptions thrown...
...But the internal logging is not working aswell
I followed every step of the troubleshooting by NLog
Has somebody an idea why NLog is still not logging anything?
--------------------- UPDATE ----------------------------
NLog is now logging with basic setup of a LogService-class:
public void Initialize(Assembly assembly, string assemblyName)
{
var location = $"{assemblyName}.NLog.config";
var stream = assembly.GetManifestResourceStream(location);
NLog.LogManager.Configuration = new XmlLoggingConfiguration(XmlReader.Create(stream), null);
NLog.Common.InternalLogger.LogFile = "C:\\Users\\MyUser\\Documents\\internalLog.log";
NLog.Common.InternalLogger.LogWriter = new StringWriter();
NLog.Common.InternalLogger.LogLevel = LogLevel.Debug;
}
But the internal log is still not showing up. As you can see I tried configuring the InternalLogger in code and also in the NLog.config. I tried putting the NLog.config in the assets-folder and in the main android-project and I set build action to respectively embedded ressource or android asset.
--------------------- 2nd UPDATE --------------------------
The InternalLogger is now working on my Android-device.
In this tutorial the internal file is logged to c://temp/... which I assume is a path on Windows. But I am still not able to achieve this during debugging. Is this even possible?

Following some additional troubleshooting tips that helped me solving my issue:
If you are using a real Andriod-device and not an emulator unplug the
debugging connection and reconnect it. The Windows-File-Explorer
sometimes is not updating the files in the folders of the device if
it is not reconnected.
Basic initializing in the code should be enough:
public void Initialize(Assembly assembly, string assemblyName)
{
var location = $"{assemblyName}.NLog.config";
var stream = assembly.GetManifestResourceStream(location);
NLog.LogManager.Configuration = new XmlLoggingConfiguration(XmlReader.Create(stream), null);
}
You should be fine by putting NLog.config as an embedded resource in the main folder of the android project. If not put it as an android asset in the assets-folder.
If it is still not logging try to set the configuration up programmatically
Also make sure your minlevel in the .config is lower than the loglevel you are using.

Related

SDL keeps failing to find font on Android

When I attempt to deploy my app using Eclipse it throws FileNotFoundException on my font, which I've now copied to both the assets/src and assets directory to be doubly sure.
I had this problem before, after succesfully integrating SDL_ttf into my Visual C++ build of the same app and transferring across to Eclipse for Android. Now I'm facing it again I thought I better write about it. The SDL_ttf source comes with a freetype folder already in place and referenced by android as external/freetype-2.4.12. DinoMage states I need to download this separately although he refers to freetype-2.4.11 being the latest. That's the only obvious difference from my VC build, apart from minor compiler intolerances.
I've got it working a bit now. I can sign the app (unsigned didn't work), disable USB debugging, and it will load the font and display a menu. From there it breaks, again, so I can't see how I'm supposed to debug it further. I'm sure I'll fix it somehow. But I'll also forget the obscura if I don't post here.
I don't know much about using the debugger with Android, but I can make suggestions otherwise.
Is your assets path really named "assetts"? If possible, I'm not sure how one would get Android and SDL to look there instead of "assets".
SDL and it's friend libs like SDL_ttf search for files local to the assets directory first and then search relative to the root directory. So I would expect that your "res/stubbornFont.ttf" will never load because it is in the resources "res" directory and SDL_ttf will not look there.
Maybe you can specify it relative to assets/, like "../res/stubbornFont.ttf", but I haven't tested that. It would work if you put the font in assets/ and loaded it as "stubbornFont.ttf".
I've think I've got closure on this.
It is possible to debug the app. By continuing it will trap several times trying to load one font. I think it stops eventually, I'm not sure. I've stepped through it from where it lands me at the throw stage. However single stepping from there begins from the synchronized statement, sorry it's Java but from my quick reference to What does 'synchronized' mean? I think this is a race condition
public final AssetFileDescriptor openFd(String fileName)
throws IOException {
synchronized (this) {
if (!mOpen) {
throw new RuntimeException("Assetmanager has been closed");
}
ParcelFileDescriptor pfd = openAssetFd(fileName, mOffsets);
if (pfd != null) {
return new AssetFileDescriptor(pfd, mOffsets[0], mOffsets[1]);
}
}
throw new FileNotFoundException("Asset file: " + fileName);//DEBUGGER traps here
}
You might be there all day single stepping that! It appears to perform all steps required of it and finally I land in:
public static ReadableByteChannel newChannel(InputStream inputStream) {
return new InputStreamChannel(inputStream);
}
No, not finally, lastly, there is
public static Context getContext() {
return mSingleton;
}
In the SDLActivity I extend.
That has a bunch of members I don't want to know about:
Luckily I discovered I can selectively "Disconnect" using a button in eclipse two along from debug/run. It has no keyboard shortcut and I'm not sure why but it will reconnect when I next trigger an exception. This is debugging as I know and love it in Android and Eclipse, still probably easier than GDB.
For arguments sake I've even replaced:
//TTF_Font *gFont = TTF_OpenFont( "res/stubbornFont.ttf", 160 );
with
TTF_Font *font=TTF_OpenFontRW(SDL_RWFromFile("res/stubbornFont.ttf", "rb"), 1, 160);//Same difference
UPDATE/EDIT
Here is the solution I was really looking for,
turning off uncaught exceptions in eclipse, it really is just that, Window->Preferences->Java->Debug and it's the very first box at the top for me.

Google Tag Manager Not Showing Values

I just started working on Google Tag Manager. I got it worked. But I faced one issue. That is, each time I edit or add some new macros, I need to create new version and publish it. Unless I am not downloading the new version and saving inside assets/tagmanager and also unless I refer with the new version name of the downloaded file, I am not able to see my updates.
Is it so? If so, I didn't understand why this is useful. Is anything done by me went wrong?
I got it worked.The issue was when we keep the json or binary inside assets folder, then on openContainer() call, Google Tag Manager will check for the saved file first. Then only it will goto the network and search. This caused issue to me. So I removed the file kept inside assets/tagmanager folder.
Also I called container.refresh() before we set value inside the singleton class.
Sample code:
ContainerOpener.openContainer(tagManager, CONTAINER_ID, OpenType.PREFER_NON_DEFAULT,
TIMEOUT_FOR_CONTAINER_OPEN_MILLISECONDS, new ContainerOpener.Notifier() {
#Override
public void containerAvailable(Container container) {
container.refresh();
// Save container for use by any other activities in the app.
WPContainerHolder.setContainer(container);
//perform your other functionalities
}
});

Setup SoftKeyBoard Cordova Plugin

I would like to hide the softkeyboard onBlur.
Therefore, I found the softkeyboard plugin, and I suppose I installed it properly, following numerous threads posts.
However, this is the first time I use a plugin for cordova, and I get this error, so I guess something is missing:
Cannot read property 'SoftKeyBoard' of undefined
This refers to the js call in the html file:
var softkeyboard = window.cordova.plugins.SoftKeyBoard;
$('#keyboard').toggle(softkeyboard.show, softkeyboard.hide);
Does not window.cordova.plugins exist?
In order to set up the plugin, I did the following:
copy SoftKeyBoard.java to src/org.apache.cordova.plugins.SoftKeyBoard. I also rewrote the first line package accordingly.
copy the js file, and link it to the html file
add this line to res/xml/config.xml:
<plugin name="SoftKeyBoard" value="org.apache.cordova.plugins.SoftKeyBoard" />
In this XML, it's located in <cordova><plugins>
Is there anything else I should have done?

Debugging pop up window "Missing Manifest?"

Im getting this error message. I created a new project and hit debug to test it. I added nothing and i get this pop up message. what could be my issue? I can create a new blank project wtih out the Controllers and Models projects in them it debugs just fine. But i need to use this solution provided to me.
New to mono droid any help will be apreciated.
You issue could be that none of the projects have been set to be deployed to a device.
Right click your Solution > Properties > Configuration Properties > Tick The Deploy checkbox for your Application Project if not already.
Also make sure to mark one of your activities with MainLauncher = true, otherwise Android does not know which Activity to start first. This is done in the [Activity()] attribute like so:
[Activity(Label = "Epic Activity", MainLauncher = true, Icon = "#drawable/icon")]
public class Activity1 : Activity {}
what could be my issue?
You are using Visual Studio... Android plays much nicer with Eclipse.
Kidding aside, every Android application requires an AndroidManifest.xml file. It looks like you are using MonoDroid, and there are docs about creating the manifest file.
Also, make sure you have built the project.
AndroidManifest.xml is generated as part of the build process, and the XML found within Properties\AndroidManifest.xml is merged with XML generated based on custom attributes.

How to import a SpriteFont into MonoGame

I'm porting a simple tetris-like XNA app to Android, using Mono For Android and MonoGame; I have followed the suggested steps in this link and so far, everything compiles well, and no relevant warnings fire up. However, upon loading the contents, a null parameter exception breaks the program at the point below in my program:
protected override void LoadContent() {
// ...
_font = Content.Load<Microsoft.Xna.Framework.Graphics.SpriteFont>("SpriteFont1");
// ...
}
The content root directory is set in the game constructor class:
public Game2 (){
Content.RootDirectory = "Content";
Content.RootDirectory = "Assets/Content"; // TEST.
//...}
And I have tried several combinations, all to no avail.
I have also tried setting the xnb files as Content as well as Android Assets in the Build Action property; having the linked, copied always, copied only if newer... etc.
Either way, my problem is that I don't really understand WHY and HOW should I do this. I'm rather new to the platform and to XNA as well, so this may very well be a newbie question, but the truth is after several hours banging my head and fists against the monitor/keyboard I feel stuck and need your help.
I have a library that supports variable-width fonts (generated by BMFont) on MonoGame. Unfortunately it is a renderer and so has other code around it. However, the basic idea is very simple. You can take a look at the loader here and the mesh builder (given a string) here. This builder supports fonts that spread characters across multiple pages, too.
Hope this helps!
MonoGame (2.5.1) throws NotImplementedException in ContentManager.Load for SpriteFont type. Have the same not resolved problem. I'm trying not to use DrawString.
For loading textures in Win32 application I use:
Content.RootDirectory = #"../../Content";
var sampleTexture = Content.Load<Texture2D>("Sample.png");
You even must not add it to solution.
For Andoind (MonoDroid) application you must add "Content" folder to your solution and set "Andtoid Asset" in "Sample.png" properties.
Content.RootDirectory = "Content";
var sampleTexture = Content.Load<Texture2D>("Sample.png");
See also:
http://monogame.codeplex.com/discussions/360468
http://monogame.codeplex.com/discussions/267900

Categories

Resources