mirror of
https://github.com/RaindropViewer/RaindropViewer.git
synced 2026-07-27 20:48:08 +00:00
Move logger init to LoggingConfiguration.cs
Log4net is rubbish.
This commit is contained in:
@@ -1,14 +0,0 @@
|
|||||||
using System.Collections;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using UnityEngine;
|
|
||||||
|
|
||||||
public class LoggerInit : MonoBehaviour
|
|
||||||
{
|
|
||||||
// Start is called before the first frame update
|
|
||||||
void Start()
|
|
||||||
{
|
|
||||||
OpenMetaverse.Logger.Log("First log. Logger.Log is working.", OpenMetaverse.Helpers.LogLevel.Info);
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@@ -1,11 +0,0 @@
|
|||||||
fileFormatVersion: 2
|
|
||||||
guid: 4295b92364fee74419e76675960a0886
|
|
||||||
MonoImporter:
|
|
||||||
externalObjects: {}
|
|
||||||
serializedVersion: 2
|
|
||||||
defaultReferences: []
|
|
||||||
executionOrder: 0
|
|
||||||
icon: {instanceID: 0}
|
|
||||||
userData:
|
|
||||||
assetBundleName:
|
|
||||||
assetBundleVariant:
|
|
||||||
@@ -1,16 +0,0 @@
|
|||||||
//using System.IO;
|
|
||||||
//using log4net.Config;
|
|
||||||
//using UnityEngine;
|
|
||||||
|
|
||||||
//public static class LoggingConfiguration
|
|
||||||
//{
|
|
||||||
// [RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.BeforeSceneLoad)]
|
|
||||||
// private static void ConfigureLogging()
|
|
||||||
// {
|
|
||||||
// XmlConfigurator.Configure(new FileInfo($"{Application.dataPath}/log4net.xml"));
|
|
||||||
// Debug.Log("xmlconfigurator called.");
|
|
||||||
|
|
||||||
|
|
||||||
// OpenMetaverse.Logger.Log("It is working!", OpenMetaverse.Helpers.LogLevel.Debug);
|
|
||||||
// }
|
|
||||||
//}
|
|
||||||
@@ -1,11 +0,0 @@
|
|||||||
fileFormatVersion: 2
|
|
||||||
guid: f53b5470f9536d1429a05939e95ac2c5
|
|
||||||
MonoImporter:
|
|
||||||
externalObjects: {}
|
|
||||||
serializedVersion: 2
|
|
||||||
defaultReferences: []
|
|
||||||
executionOrder: 0
|
|
||||||
icon: {instanceID: 0}
|
|
||||||
userData:
|
|
||||||
assetBundleName:
|
|
||||||
assetBundleVariant:
|
|
||||||
@@ -82,13 +82,12 @@ namespace OpenMetaverse
|
|||||||
//};
|
//};
|
||||||
//BasicConfigurator.Configure(LogManager.GetRepository(Assembly.GetCallingAssembly()), appender);
|
//BasicConfigurator.Configure(LogManager.GetRepository(Assembly.GetCallingAssembly()), appender);
|
||||||
|
|
||||||
//this is the new version, i hope it works.
|
//1. log to unity console.
|
||||||
var appender = new UnityDebugAppender();
|
var unityDebugAppender = new UnityDebugAppender();
|
||||||
|
unityDebugAppender.Layout = new PatternLayout("%date{HH:mm:ss} [%level] - %message");
|
||||||
appender.Layout = new PatternLayout("%date{HH:mm:ss} [%level] - %message");
|
|
||||||
//appender.Layout = new PatternLayout("%timestamp [%thread] %-5level - %message%newline");
|
//appender.Layout = new PatternLayout("%timestamp [%thread] %-5level - %message%newline");
|
||||||
BasicConfigurator.Configure(appender);
|
BasicConfigurator.Configure(unityDebugAppender);
|
||||||
|
|
||||||
|
|
||||||
if (Settings.LOG_LEVEL != Helpers.LogLevel.None)
|
if (Settings.LOG_LEVEL != Helpers.LogLevel.None)
|
||||||
LogInstance.Warn("No log configuration found, defaulting to console logging");
|
LogInstance.Warn("No log configuration found, defaulting to console logging");
|
||||||
|
|||||||
@@ -0,0 +1,76 @@
|
|||||||
|
using System.IO;
|
||||||
|
using Disk;
|
||||||
|
using log4net;
|
||||||
|
using log4net.Appender;
|
||||||
|
using log4net.Layout;
|
||||||
|
using log4net.Repository.Hierarchy;
|
||||||
|
using Raindrop.Services.Bootstrap;
|
||||||
|
using UnityEngine;
|
||||||
|
|
||||||
|
public static class LoggingConfiguration
|
||||||
|
{
|
||||||
|
[RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.BeforeSceneLoad)]
|
||||||
|
private static void Configure()
|
||||||
|
{
|
||||||
|
// var key = "log4net.Internal.Debug";
|
||||||
|
// string value = true.ToString();
|
||||||
|
//
|
||||||
|
// try
|
||||||
|
// {
|
||||||
|
// var configFile = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
|
||||||
|
// var settings = configFile.AppSettings.Settings;
|
||||||
|
// if (settings[key] == null)
|
||||||
|
// {
|
||||||
|
// settings.Add(key, value);
|
||||||
|
// }
|
||||||
|
// else
|
||||||
|
// {
|
||||||
|
// settings[key].Value = value;
|
||||||
|
// }
|
||||||
|
// configFile.Save(ConfigurationSaveMode.Modified);
|
||||||
|
// ConfigurationManager.RefreshSection(configFile.AppSettings.SectionInformation.Name);
|
||||||
|
// }
|
||||||
|
// catch (ConfigurationErrorsException)
|
||||||
|
// {
|
||||||
|
// Debug.Log("Error writing app settings");
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
|
||||||
|
Debug.Log("Application is configuring the global logger. \n" +
|
||||||
|
"We are using configuration file at: "
|
||||||
|
+ $"{DirectoryHelpers.GetInternalCacheDir()}/log4net.xml");
|
||||||
|
// var res = XmlConfigurator.Configure(new FileInfo($"{DirectoryHelpers.GetInternalCacheDir()}/log4net.xml"));
|
||||||
|
ConfigureLoggers(
|
||||||
|
Path.Combine(DirectoryHelpers.GetInternalCacheDir(), "log.txt"));
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
public static void ConfigureLoggers(string filepath)
|
||||||
|
{
|
||||||
|
// log4net.Config.XmlConfigurator.Configure();
|
||||||
|
Hierarchy hierarchy = (Hierarchy)LogManager.GetRepository();
|
||||||
|
|
||||||
|
//1. log to unity console.
|
||||||
|
var unityDebugAppender = new UnityDebugAppender();
|
||||||
|
unityDebugAppender.Layout = new PatternLayout("%date{HH:mm:ss} [%level] - %message");
|
||||||
|
//appender.Layout = new PatternLayout("%timestamp [%thread] %-5level - %message%newline");
|
||||||
|
// BasicConfigurator.Configure(unityDebugAppender);
|
||||||
|
hierarchy.Root.AddAppender(unityDebugAppender);
|
||||||
|
|
||||||
|
|
||||||
|
var logFileAppender = new RollingFileAppender();
|
||||||
|
logFileAppender.Layout = new PatternLayout("%date{HH:mm:ss} [%level] - %message%newline");
|
||||||
|
logFileAppender.File = filepath;
|
||||||
|
logFileAppender.AppendToFile = true;
|
||||||
|
logFileAppender.RollingStyle = RollingFileAppender.RollingMode.Size;
|
||||||
|
logFileAppender.MaxSizeRollBackups = 10;
|
||||||
|
logFileAppender.MaxFileSize = 250 * 1000; // 250KB
|
||||||
|
logFileAppender.StaticLogFileName = true;
|
||||||
|
logFileAppender.ActivateOptions();
|
||||||
|
// XmlConfigurator.Configure();
|
||||||
|
hierarchy.Root.AddAppender(logFileAppender);
|
||||||
|
|
||||||
|
hierarchy.Configured = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: c6878c9d86df41169b650f796c06e270
|
||||||
|
timeCreated: 1546859428
|
||||||
+8
-8
@@ -1,12 +1,12 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<log4net>
|
<log4net>
|
||||||
<appender name="RaindropLog" type="Raindrop.RaindropAppender">
|
<appender name="UnityDebugAppender" type="UnityDebugAppender">
|
||||||
<layout type="log4net.Layout.PatternLayout">
|
<layout type="log4net.Layout.PatternLayout, log4net">
|
||||||
<conversionPattern value="%date{HH:mm:ss} [%level] - %message" />
|
<conversionPattern value="%d{ABSOLUTE} %-5p %c{1}:%L - %m%n"/>
|
||||||
</layout>
|
</layout>
|
||||||
</appender>
|
</appender>
|
||||||
<root>
|
<root>
|
||||||
<level value="ALL" />
|
<level value="DEBUG"/>
|
||||||
<appender-ref ref="RaindropLog" />
|
<appender-ref ref="UnityDebugAppender"/>
|
||||||
</root>
|
</root>
|
||||||
</log4net>
|
</log4net>
|
||||||
|
|
||||||
@@ -1,7 +1,3 @@
|
|||||||
fileFormatVersion: 2
|
fileFormatVersion: 2
|
||||||
guid: e86452698ba1c0946826237d6247b4b7
|
guid: 3ad4e357e4824d6f95265a0fcecfce8f
|
||||||
TextScriptImporter:
|
timeCreated: 1546859523
|
||||||
externalObjects: {}
|
|
||||||
userData:
|
|
||||||
assetBundleName:
|
|
||||||
assetBundleVariant:
|
|
||||||
Reference in New Issue
Block a user