NLog异常的日志到文件(Unity项目)
本文关键字:Unity 项目 文件 异常 日志 NLog | 更新日期: 2023-09-27 18:18:06
我正在使用NLog的编程配置,每当应该将日志文件写入时,都会遇到以下错误:
ArgumentOutOfRangeException:参数超出范围。System.Security.AccessControl.AuthorizationRule . .男星(System.Security.Principal。IdentityReference标识,Int32继承的标志,继承的标志,PropagationFlags(传播标志/用户/builduser/buildslave/mono/构建/mcs/类/corlib/System.Security.AccessControl/AuthorizationRule.cs: 61)System.Security.AccessControl.AccessRule . .男星(System.Security.Principal。IdentityReference标识,Int32继承的标志,继承的标志,PropagationFlags PropagationFlags, AccessControlType类型)System.Security.AccessControl.MutexAccessRule . .男星(System.Security.Principal。IdentityReference标识,MutexRightseventRights, AccessControlType类型)NLog.Internal.FileAppenders.BaseFileAppender.CreateSharableMutex(系统。字符串mutexNamePrefix)NLog.Internal.FileAppenders.BaseFileAppender.CreateSharableArchiveMutex()NLog.Internal.FileAppenders.RetryingMultiProcessFileAppender.CreateArchiveMutex() nlog . internal . fileappender . basefileappender .…字符串文件名,ICreateFileParametersNLog.Internal.FileAppenders.RetryingMultiProcessFileAppender . .男星(系统。字符串文件名,ICreateFileParameters参数NLog.Internal.FileAppenders.RetryingMultiProcessFileAppender + Factory.NLog.Internal.FileAppenders.IFileAppenderFactory.Open(系统。字符串文件名,ICreateFileParameters参数NLog.Internal.FileAppenders.FileAppenderCache.AllocateAppender(系统。nlog . targets . filettarget . writetofile(系统。字符串文件名,NLog。LogEventInfo logEventByte []nlog . targets . filettarget . processlogevent(NLog。LogEventInfo logEvent文件名,系统。Byte []NLog. targets . filettarget . write (NLog. target . write)LogEventInfoNLog.Targets.Target.Write (AsyncLogEventInfo logEvent)
谷歌不知道任何关于这个错误,据我所知。下面是我的配置代码:
public static void SetupLogging()
{
// Can unity debug be redirected to go through Nlog?
var config = new LoggingConfiguration();
var consoleTarget = new ConsoleTarget("console");
config.AddTarget("console", consoleTarget);
//var logsPath = UtilsIO.GetResourcesPath(UtilsIO.ResourceType.Logs, "_logs");
var logsPath = @"d:'jem'temp'_logs";
var dir = logsPath + "''app" + "''" + Environment.UserName;
if (!Directory.Exists(dir))
{
Directory.CreateDirectory(dir);
}
var filepath = Path.Combine(dir, Guid.NewGuid() + ".log");
var fileTarget = new FileTarget("file")
{
FileName = filepath,
Layout = "${date:format=yyyyMMddHHmmss} ${message}"
};
config.AddTarget("file", fileTarget);
var rule1 = new LoggingRule("*", LogLevel.Debug, consoleTarget);
config.LoggingRules.Add(rule1);
var rule2 = new LoggingRule("*", LogLevel.Debug, fileTarget);
config.LoggingRules.Add(rule2);
InternalLogger.LogToConsole = true;
LogManager.ThrowExceptions = true;
LogManager.Configuration = config;
}
我是这样实例化日志记录器的:
private static NLog.Logger logger = LogManager.GetLogger("file");
我是这样使用实例化的:
logger.Debug("Hello world????");
我试过使用ImpersonatingTargetWrapper,但得到同样的错误。我已经给了'Everyone'对根目录的全部权限。我也尝试过配置文件来开始,但这也没有帮助。我一直在思考这个问题,有人有什么建议吗?
NLog 4.4.1现在执行MONO版本的运行时检测,并避免在不运行MONO版本时使用命名互斥锁。4或更新版本(Unity运行MONO版本)。2)