diff --git a/.github/workflows/discord.yml b/.github/workflows/discord.yml index d08a538..bd1ae82 100644 --- a/.github/workflows/discord.yml +++ b/.github/workflows/discord.yml @@ -20,4 +20,4 @@ jobs: secrets: webhook_url: ${{ secrets.VALHEIM_DISCORD_TITANS_WEBHOOK_URL }} with: - repo_name: Placeholder + repo_name: Digitalroot.Unity3d.Log diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index ddc8d44..b20f732 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -20,22 +20,14 @@ jobs: secrets: aws-access-key-id: ${{ secrets.NUGET_S3_REPO_KEY_ID }} aws-secret-access-key: ${{ secrets.NUGET_S3_REPO_KEY_SECRET }} - #nexus-api-key: ${{ secrets.NEXUS_API_KEY }} - #nexus-cookies-header: ${{ secrets.NEXUS_COOKIE_HEADER }} #nuget-org-key: ${{ secrets.NUGET_ORG_PAT }} with: - sln-file-name: Digitalroot.Valheim.Common.Placeholder - proj-file-name: Digitalroot.Valheim.Common.Placeholder - #src-path: src - #unit-test-path: UnitTests - #skip-unit-tests: true + sln-file-name: Digitalroot.Unity3d.Log + proj-file-name: Digitalroot.Unity3d.Log + skip-unit-tests: true #force-assembly-version: true #create-github-release: false - #aws-region: us-west-2 - #is-nuget-package: false - #nuget-gh-upload: true - #nuget-s3-upload: true + nuget-gh-upload: true + nuget-s3-upload: true #nuget-org-upload: true - #nexus-enable-upload: true - #nexus-mod-id: 000 \ No newline at end of file diff --git a/src/Digitalroot.Valheim.ModTemplate.sln b/src/Digitalroot.Unity3d.Log.sln similarity index 76% rename from src/Digitalroot.Valheim.ModTemplate.sln rename to src/Digitalroot.Unity3d.Log.sln index 591e3ca..fe69eec 100644 --- a/src/Digitalroot.Valheim.ModTemplate.sln +++ b/src/Digitalroot.Unity3d.Log.sln @@ -36,7 +36,19 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "ico", "ico", "{C66A8E3B-31D ico\ValheimRcon_color.png = ico\ValheimRcon_color.png EndProjectSection EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Digitalroot.Unity3d.Log", "Digitalroot.Unity3d.Log\Digitalroot.Unity3d.Log.csproj", "{0FDC39E3-D8A6-434A-9DAD-5EF5A48162E5}" +EndProject Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {0FDC39E3-D8A6-434A-9DAD-5EF5A48162E5}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {0FDC39E3-D8A6-434A-9DAD-5EF5A48162E5}.Debug|Any CPU.Build.0 = Debug|Any CPU + {0FDC39E3-D8A6-434A-9DAD-5EF5A48162E5}.Release|Any CPU.ActiveCfg = Release|Any CPU + {0FDC39E3-D8A6-434A-9DAD-5EF5A48162E5}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE EndGlobalSection diff --git a/src/Digitalroot.Unity3d.Log/Digitalroot.Unity3d.Log.csproj b/src/Digitalroot.Unity3d.Log/Digitalroot.Unity3d.Log.csproj new file mode 100644 index 0000000..70e0b74 --- /dev/null +++ b/src/Digitalroot.Unity3d.Log/Digitalroot.Unity3d.Log.csproj @@ -0,0 +1,59 @@ + + + + Digitalroot.Unity3d.Log + net462 + 9 + Digitalroot.Unity3d.Log + Digitalroot.Unity3d.Log + false + true + AGPL-3.0-or-later + Copyright © Digitalroot Technologies 2022 + https://github.com/Digitalroot-Valheim/Digitalroot.Unity3d.Log + https://github.com/Digitalroot-Valheim/Digitalroot.Unity3d.Log + git + ValheimRcon_black.png + + unity, digitalroot, log, logging + Digitalroot + Digitalroot Technologies + Digitalroot Unity3d Log + Logging Unity + Initial Release + en-US + true + 1.0.0 + + https://nuget.bepinex.dev/v3/index.json; + https://digitalroot-valheim-nuget.s3.us-west-2.amazonaws.com/index.json + + False + embedded + + + + true + DEBUG;TRACE + + + + true + TRACE + + + + + True + + + + + + + all + compile + + + + diff --git a/src/Digitalroot.Unity3d.Log/TraceLogger.cs b/src/Digitalroot.Unity3d.Log/TraceLogger.cs new file mode 100644 index 0000000..49b1ad2 --- /dev/null +++ b/src/Digitalroot.Unity3d.Log/TraceLogger.cs @@ -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(); + } + } + } +} diff --git a/src/Digitalroot.Unity3d.Log/packages.lock.json b/src/Digitalroot.Unity3d.Log/packages.lock.json new file mode 100644 index 0000000..ff7c884 --- /dev/null +++ b/src/Digitalroot.Unity3d.Log/packages.lock.json @@ -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==" + } + } + } +} \ No newline at end of file