我使用NLog进行编程配置,并且每当应该将日志文件写入时遇到以下错误:
ArgumentOutOfRangeException:参数超出范围。 System.Security.AccessControl.AuthorizationRule..ctor (System.Security.Principal.IdentityReference标识,Int32 accessMask,Boolean isInherited,InheritanceFlags inheritanceFlags, PropagationFlags propagationFlags)(at /Users/builduser/buildslave/mono/build/mcs/class/corlib/System.Security.AccessControl/AuthorizationRule.cs:61) System.Security.AccessControl.AccessRule..ctor (System.Security.Principal.IdentityReference标识,Int32 accessMask,Boolean isInherited,InheritanceFlags inheritanceFlags, PropagationFlags propagationFlags,AccessControlType type) System.Security.AccessControl.MutexAccessRule..ctor (System.Security.Principal.IdentityReference标识,MutexRights eventRights,AccessControlType类型) NLog.Internal.FileAppenders.BaseFileAppender.CreateSharableMutex (System.String mutexNamePrefix) NLog.Internal.FileAppenders.BaseFileAppender.CreateSharableArchiveMutex () NLog.Internal.FileAppenders.RetryingMultiProcessFileAppender.CreateArchiveMutex ()NLog.Internal.FileAppenders.BaseFileAppender..ctor(System.String fileName,ICreateFileParameters createParameters) NLog.Internal.FileAppenders.RetryingMultiProcessFileAppender..ctor (System.String fileName,ICreateFileParameters参数) NLog.Internal.FileAppenders.RetryingMultiProcessFileAppender + Factory.NLog.Internal.FileAppenders.IFileAppenderFactory.Open (System.String fileName,ICreateFileParameters参数) NLog.Internal.FileAppenders.FileAppenderCache.AllocateAppender (System.String fileName)NLog.Targets.FileTarget.WriteToFile (System.String fileName,NLog.LogEventInfo logEvent,System.Byte [] bytes,Boolean justData)NLog.Targets.FileTarget.ProcessLogEvent (NLog.LogEventInfo logEvent,System.String fileName,System.Byte [] bytesToWrite)NLog.Targets.FileTarget.Write(NLog.LogEventInfo) logEvent)NLog.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但得到了同样的错误。我已经给出了“每个人”#39;根目录的完全权限。我也试过配置文件开始,但这也没有帮助。我已经对这个问题猛烈抨击了一下 - 任何人都有任何建议吗?
答案 0 :(得分:1)
NLog 4.4.1现在执行MONO版本的运行时检测,并且如果没有运行MONO ver,则避免使用命名的互斥锁。 4或更新(Unity正在运行MONO版本2)