generated from Digitalroot-Valheim/Digitalroot.Valheim.ModRepoTemplate
-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
368a9c0
commit 74a5119
Showing
6 changed files
with
155 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
59 changes: 59 additions & 0 deletions
59
src/Digitalroot.Unity3d.Log/Digitalroot.Unity3d.Log.csproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<AssemblyName>Digitalroot.Unity3d.Log</AssemblyName> | ||
<TargetFramework>net462</TargetFramework> | ||
<LangVersion>9</LangVersion> | ||
<PackageId>Digitalroot.Unity3d.Log</PackageId> | ||
<RootNamespace>Digitalroot.Unity3d.Log</RootNamespace> | ||
<GeneratePackageOnBuild>false</GeneratePackageOnBuild> | ||
<PackageRequireLicenseAcceptance>true</PackageRequireLicenseAcceptance> | ||
<PackageLicenseExpression>AGPL-3.0-or-later</PackageLicenseExpression> | ||
<Copyright>Copyright © Digitalroot Technologies 2022</Copyright> | ||
<PackageProjectUrl>https://github.com/Digitalroot-Valheim/Digitalroot.Unity3d.Log</PackageProjectUrl> | ||
<RepositoryUrl>https://github.com/Digitalroot-Valheim/Digitalroot.Unity3d.Log</RepositoryUrl> | ||
<RepositoryType>git</RepositoryType> | ||
<PackageIcon>ValheimRcon_black.png</PackageIcon> | ||
<PackageIconUrl /> | ||
<PackageTags>unity, digitalroot, log, logging</PackageTags> | ||
<Authors>Digitalroot</Authors> | ||
<Company>Digitalroot Technologies</Company> | ||
<Product>Digitalroot Unity3d Log</Product> | ||
<Description>Logging Unity</Description> | ||
<PackageReleaseNotes>Initial Release</PackageReleaseNotes> | ||
<NeutralLanguage>en-US</NeutralLanguage> | ||
<RestorePackagesWithLockFile>true</RestorePackagesWithLockFile> | ||
<VersionPrefix>1.0.0</VersionPrefix> | ||
<RestoreAdditionalProjectSources> | ||
https://nuget.bepinex.dev/v3/index.json; | ||
https://digitalroot-valheim-nuget.s3.us-west-2.amazonaws.com/index.json | ||
</RestoreAdditionalProjectSources> | ||
<IsPublishable>False</IsPublishable> | ||
<DebugType>embedded</DebugType> | ||
</PropertyGroup> | ||
|
||
<PropertyGroup Condition="'$(Configuration)|$(TargetFramework)|$(Platform)'=='Debug|net462|AnyCPU'"> | ||
<AllowUnsafeBlocks>true</AllowUnsafeBlocks> | ||
<DefineConstants>DEBUG;TRACE</DefineConstants> | ||
</PropertyGroup> | ||
|
||
<PropertyGroup Condition="'$(Configuration)|$(TargetFramework)|$(Platform)'=='Release|net462|AnyCPU'"> | ||
<AllowUnsafeBlocks>true</AllowUnsafeBlocks> | ||
<DefineConstants>TRACE</DefineConstants> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<None Include="..\ico\ValheimRcon_black.png"> | ||
<Pack>True</Pack> | ||
<PackagePath></PackagePath> | ||
</None> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="UnityEngine.Modules" Version="[2019.4.31]"> | ||
<PrivateAssets>all</PrivateAssets> | ||
<IncludeAssets>compile</IncludeAssets> | ||
</PackageReference> | ||
</ItemGroup> | ||
|
||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
using System; | ||
using System.IO; | ||
using System.Text; | ||
using System.Threading; | ||
using UnityEngine; | ||
|
||
namespace Digitalroot.Unity3d.Log | ||
{ | ||
public class TraceLogger | ||
{ | ||
private readonly FileInfo _traceFileInfo; | ||
private readonly string _source; | ||
public bool IsTraceEnabled { get; private set; } | ||
|
||
public TraceLogger(string source, bool enableTrace) | ||
{ | ||
try | ||
{ | ||
_source = source; | ||
IsTraceEnabled = enableTrace; | ||
var logDirectoryInfo = new DirectoryInfo(Application.dataPath); | ||
if (!logDirectoryInfo.Exists) throw new DirectoryNotFoundException($"{logDirectoryInfo.FullName} does not exist."); | ||
|
||
var gamePath = logDirectoryInfo.Parent?.FullName ?? throw new DirectoryNotFoundException($"_logDirectoryInfo.Parent of {logDirectoryInfo.FullName} is null"); | ||
var bepInExDirectoryInfo = new DirectoryInfo(Path.Combine(gamePath, "BepInEx")); | ||
if (!bepInExDirectoryInfo.Exists) throw new DirectoryNotFoundException($"{bepInExDirectoryInfo.FullName} does not exist."); | ||
var bepInExLogsDirectoryInfo = new DirectoryInfo(Path.Combine(bepInExDirectoryInfo.FullName, "logs")); | ||
if (!bepInExLogsDirectoryInfo.Exists) bepInExLogsDirectoryInfo.Create(); | ||
|
||
_traceFileInfo = new FileInfo(Path.Combine(bepInExLogsDirectoryInfo.FullName, $"{_source}.Trace.log")); | ||
} | ||
catch (Exception e) | ||
{ | ||
Debug.LogException(e); | ||
} | ||
} | ||
|
||
public void EnableTrace() | ||
{ | ||
IsTraceEnabled = true; | ||
} | ||
|
||
public void DisableTrace() | ||
{ | ||
IsTraceEnabled = false; | ||
} | ||
|
||
public void Trace(string message) | ||
{ | ||
if (!IsTraceEnabled) return; | ||
|
||
using var mutex = new Mutex(false, $"Digitalroot.Unity3d.TraceLogger.{_source}"); | ||
mutex.WaitOne(); | ||
try | ||
{ | ||
var msg = $"[{"Trace",-7}:{_source,10}] {message}{Environment.NewLine}"; | ||
File.AppendAllText(_traceFileInfo.FullName, msg, Encoding.UTF8); | ||
} | ||
finally | ||
{ | ||
mutex.ReleaseMutex(); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
{ | ||
"version": 1, | ||
"dependencies": { | ||
".NETFramework,Version=v4.6.2": { | ||
"UnityEngine.Modules": { | ||
"type": "Direct", | ||
"requested": "[2019.4.31, 2019.4.31]", | ||
"resolved": "2019.4.31", | ||
"contentHash": "xZjdfGGzZw6nnrn4auRNis6WnAlsvqY1XXioEGJnSku+CylESgEt/sTLYlrbrQ0srnLfSCfx80vR8z4SsI1EuQ==" | ||
} | ||
} | ||
} | ||
} |