线程安全记录到文本文件

时间:2013-11-14 01:51:58

标签: c# multithreading asp.net-mvc-3 logging concurrency

尝试使用Microsoft.VisualBasic.Logging.FileLogTraceListener时 该对象正在访问ctor中的某个文件夹(并在其中写入内容!)。

ctor发生了异常

现在有一些示例代码......

FileLogTraceListener logger = new FileLogTraceListener("theName");
Writer.BaseFileName = "Writer";
Writer.CustomLocation = HttpContext.Current.Server.MapPath("/logs");
Writer.LogFileCreationSchedule = LogFileCreationScheduleOption.Weekly;
Writer.TraceOutputOptions = TraceOptions.Timestamp;
Writer.AutoFlush = true;
Writer.Delimiter = "|";
Writer.DiskSpaceExhaustedBehavior = DiskSpaceExhaustedOption.DiscardMessages;
Writer.Location = LogFileLocation.Custom;
Writer.Encoding = UTF8Encoding.UTF8;
Writer.IncludeHostName = false;
Writer.MaxFileSize = (1024 * 1024) * 5;            

Writer.WriteLine(message, category);

[UnauthorizedAccessException: Access to the path '\Microsoft Corporation\Internet Information Services\7.0.6000.16386' is denied.]
System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath) +10797222
System.IO.Directory.InternalCreateDirectory(String fullPath, String path, Object dirSecurityObj, Boolean checkHost) +10589262
System.IO.Directory.InternalCreateDirectoryHelper(String path, Boolean checkHost) +136
System.IO.Directory.CreateDirectory(String path) +33

帮助任何人?

0 个答案:

没有答案