Advertisement
pragmaticsystematic

Appender Code

Oct 4th, 2019
547
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.04 KB | None | 0 0
  1. using System;
  2. using System.IO;
  3. using log4net.Appender;
  4. using log4net.Core;
  5. using UnityEngine;
  6.  
  7. public class UnityDebugAppender : AppenderSkeleton
  8. {
  9.     protected override void Append(LoggingEvent loggingEvent)
  10.     {
  11.  
  12.         var fileName = loggingEvent.LocationInformation.FileName;
  13.         var path = GetRelativePath(fileName, "D:/Windows/Documents/Unity/Prehistorik Era");
  14.         var message = RenderLoggingEvent(loggingEvent);
  15.         Debug.Log($"{message} (at {path}:)");
  16.     }
  17.    
  18.     string GetRelativePath(string filespec, string folder)
  19.     {
  20.         Uri pathUri = new Uri(filespec);
  21.         // Folders must end in a slash
  22.         if (!folder.EndsWith(Path.DirectorySeparatorChar.ToString()))
  23.         {
  24.             folder += Path.DirectorySeparatorChar;
  25.         }
  26.         Uri folderUri = new Uri(folder);
  27.         return Uri.UnescapeDataString(folderUri.MakeRelativeUri(pathUri).ToString());
  28. //        return Uri.UnescapeDataString(folderUri.MakeRelativeUri(pathUri).ToString().Replace('/', Path.DirectorySeparatorChar));
  29.     }
  30. }a
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement