How to control AutoLogger?
Closed this issue ยท 23 comments
I get UnauthorizedAccessException and DirectoryNotFoundException in UWP app, because with apps, you can't store data (SignalGoDiagnostic\DataExchanger Logs.log
) directly in app folder.
How can I put the logs in a writeable folder?
Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData)
or Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData)
AutoLogger class has "DirectoryLocation" and "DirectoryName" and "FileName" properties you can change them, or you can disable Logger with IsEnabled = false property.
example:
AutoLogger.Default.DirectoryLocation = "C:\test";
AutoLogger.Default.DirectoryName = "internalFolder";
AutoLogger.Default.FileName = "test.log";
file will save to "C:\test\internalFolder\test.log"
but how can I control this? I see this exception in CustomICollectionCreationConverter ( this is a great call, to avoid the Newtonsoft.Json.JsonSerializationException: Self referencing loop detected
issue with SignalR ๐๐๐).
What do I have to call to change it? in CLient Provider? ๐คทโโ๏ธ ๐ค
AutoLogger.Default is for public logs but for CustomICollectionCreationConverter you can change it with this example:
CustomICollectionCreationConverter.AutoLogger.changedomething
you can write and change autologger setting before start services.
But where do I have to call this? provide a sample.
before you start your client provider.
var clientProvider = new ClientProvider();
//do something register services etc
CustomICollectionCreationConverter.AutoLogger.DirectoryLocation = "C:\test";
CustomICollectionCreationConverter.AutoLogger.DirectoryName = "internalFolder";
CustomICollectionCreationConverter.AutoLogger.FileName = "test.log";
//change another property
doesn't work, DirectoryLocation is declared as static, the 2 others are not:
error CS0176: Member 'AutoLogger.DirectoryLocation' cannot be accessed with an instance reference; qualify it with a type name instead
ok change it with this example:
SignalGo.Shared.Log.AutoLogger.DirectoryLocation = "C:\test";
this is public path for all logs
I tried it, it compiles, but at runtime the logger still tries to write to current app directory
System.UnauthorizedAccessException: 'Access to the path 'C:\Users\USERNAME\AppData\Local\DevelopmentFiles\Foo.AppVS.Debug_x86.USERNAME\SignalGoDiagnostic' is denied.'
instead of the configured Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData);
which has value C:\Users\USERNAME\AppData\Local\Packages\Foo.App_3pxpm51tcd4r6\LocalState
SignalGo.Shared.Log.AutoLogger.DirectoryLocation = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData);
CustomICollectionCreationConverter.AutoLogger.DirectoryName = "SignalGoDiag";
CustomICollectionCreationConverter.AutoLogger.FileName = "test.log";
I think its not signalgo stuff, in UWP you must know where you want save data or get access from user for that folders.
set CustomICollectionCreationConverter.AutoLogger.DirectoryName = null to save it in root folder instade of SignalGoDiagnostic folder
this folder is writeable from apps. Also Xamarin.Essentials returns this as writeable path. Setting DirectoryName to null makes no diff, same error.
Your Autologger resets all time to root dir of application, no matter what I set.
Please release a hotfix for v5 to turn all logging off with an option until this gets improved in v6.
but i don't undrestand why you getting that error when everything is in try catch?
https://github.com/SignalGo/SignalGo-full-net/blob/version5/SignalGo.Shared/Log/AutoLogger.cs
I configured VS to stop at both exceptions, without doing this, app crashes with Outofmemory exception and debug output only shows UnauthorizedAccessException and DirectoryNotFoundException occured.
use this example for uwp:
SignalGo.Shared.Log.AutoLogger.DirectoryLocation = System.IO.Path.Combine(ApplicationData.Current.LocalFolder.Path, "MyAppFolder");
if (!ExistsDirectory(SignalGo.Shared.Log.AutoLogger.DirectoryLocation))
CreateDirectory(SignalGo.Shared.Log.AutoLogger.DirectoryLocation);
public bool ExistsDirectory(string path)
{
try
{
string folder = Path.GetDirectoryName(path);
string name = Path.GetFileName(path);
StorageFolder accessFolder = StorageFolder.GetFolderFromPathAsync(folder).AsTask().GetAwaiter().GetResult();
IStorageItem item = accessFolder.TryGetItemAsync(name).AsTask().GetAwaiter().GetResult();
return (item != null);
}
catch
{
return false;
}
}
public void CreateDirectory(string path)
{
string folder = Path.GetDirectoryName(path);
string name = Path.GetFileName(path);
StorageFolder accessFolder = StorageFolder.GetFolderFromPathAsync(folder).AsTask().GetAwaiter().GetResult();
accessFolder.CreateFolderAsync(name).AsTask().GetAwaiter().GetResult();
}
this is for UWP only, I need it for Xamarin.Forms
I think its works on another like android and ios, because you must create not exists folder manualy in uwp like my example.
mybe in android your app will not crash.
in Xamarin Forms, the apps for UWP, Android, iOS, Tizen are stubs, they include NO additional code, they only load a .net standard 2.0 DLL which includes all code, pages and so on. So I can't add UWP specific code to the shared codebase.
I tested my Android part of the app and here the complete Android tablet hangs up.
So how can I disable the logging at all or redirect to Debug Output Window? I only want to test if the app works
use:
CustomICollectionCreationConverter.AutoLogger.IsEnabled =false;
AutoLogger.Default.IsEnabled = false;
again, this doesn't work
error CS0176: Member 'AutoLogger.IsEnabled' cannot be accessed with an instance reference; qualify it with a type name instead
Show me your code that has error pls.
I just pasted your 2 lines before I call clientProvider.ConnectAsyncAutoReconnect
ok I'm sorry, copy this:
SignalGo.Shared.Log.AutoLogger.IsEnabled = false;
ok, this works. Now I no longer crash.
But I noticed high CPU usage because of SignalGo.Shared.dll!SignalGo.Shared.Helpers.ToLocalDateTimeConvertor::WriteJson
Line # | DPC/ISR | Process | Stack Tag | Stack | Count | TimeStamp | % Weight |
---|---|---|---|---|---|---|---|
97 | | | | | | | | | | | | | | | | | | |- Newtonsoft.Json.dll!Newtonsoft.Json.Serialization.JsonSerializerInternalWriter::SerializeObject | 11971 | 10,26 | ||||
98 | | | | | | | | | | | | | | | | | | | |- Newtonsoft.Json.dll!Newtonsoft.Json.Serialization.JsonSerializerInternalWriter::SerializeValue | 11702 | 10,03 | ||||
99 | | | | | | | | | | | | | | | | | | | | |- Newtonsoft.Json.dll!Newtonsoft.Json.Serialization.JsonSerializerInternalWriter::SerializeList | 11341 | 9,72 | ||||
100 | | | | | | | | | | | | | | | | | | | | | |- Newtonsoft.Json.dll!Newtonsoft.Json.Serialization.JsonSerializerInternalWriter::SerializeValue | 10775 | 9,24 | ||||
101 | | | | | | | | | | | | | | | | | | | | | | |- Newtonsoft.Json.dll!Newtonsoft.Json.Serialization.JsonSerializerInternalWriter::SerializeObject | 10531 | 9,03 | ||||
102 | | | | | | | | | | | | | | | | | | | | | | | |- Newtonsoft.Json.dll!Newtonsoft.Json.Serialization.JsonSerializerInternalWriter::SerializeValue | 4906 | 4,21 | ||||
103 | | | | | | | | | | | | | | | | | | | | | | | | |- Newtonsoft.Json.dll!Newtonsoft.Json.Serialization.JsonSerializerInternalWriter::SerializeConvertable | 2423 | 2,08 | ||||
104 | | | | | | | | | | | | | | | | | | | | | | | | | |- SignalGo.Shared.dll!SignalGo.Shared.Helpers.ToLocalDateTimeConvertor::WriteJson | 2379 | 2,04 | ||||
105 | | | | | | | | | | | | | | | | | | | | | | | | | | |- Newtonsoft.Json.dll!Newtonsoft.Json.JsonTextWriter::WriteValue | 1247 | 1,07 | ||||
106 | | | | | | | | | | | | | | | | | | | | | | | | | | | |- Newtonsoft.Json.dll!Newtonsoft.Json.JsonTextWriter::WriteValueToBuffer | 1164 | 1,00 | ||||
107 | | | | | | | | | | | | | | | | | | | | | | | | | | | | |- Newtonsoft.Json.dll!Newtonsoft.Json.Utilities.DateTimeUtils::WriteDateTimeString | 1144 | 0,98 | ||||
108 | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |- System.Private.CoreLib.dll!System.TimeZoneInfo.GetUtcOffset(System.DateTime, System.TimeZoneInfoOptions, CachedData)$##60017DD | 756 | 0,65 | ||||
109 | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |- System.Private.CoreLib.dll!System.TimeZoneInfo.GetUtcOffset(System.DateTime, System.TimeZoneInfo, System.TimeZoneInfoOptions)$##6001813 | 736 | 0,63 |
why do you call this?
for fix some bugs and getting data from ef core and sending to javascript clients we had problem in true datetime, so we made this to fix that problem.