コード例 #1
0
        /// <summary>
        /// Creates a file target for log events using the appName prefix, followed by the suffixes
        /// joined with dots. Logs are written to the GGP SDK logs directory.
        /// </summary>
        /// <remarks>Log file names must be unique to this instance of this executable.</remarks>
        /// <param name="appName">prefix to uniquely identify this executable</param>
        /// <param name="suffixes">one or more strings to uniquely identify this log file</param>
        private static FileTarget CreateBaseFileTarget(string appName, params string[] suffixes)
        {
            if (suffixes.Length < 1)
            {
                throw new ArgumentException("need at least 1 suffix", nameof(suffixes));
            }
            var suffix = string.Join(".", suffixes);

            var logPath    = SDKUtil.GetLoggingPath();
            var fileTarget = new FileTarget();

            fileTarget.FileName =
                string.Format("{0}/{1}.{2}.log", logPath, appName, suffix);
            // Set up an archive file name regardless if archiving will be used or not.
            // https://github.com/nlog/NLog/wiki/File-target#archival-options
            // Note that {{#}} gets converted to {#} in the formatted string, which is then
            // replaced by the archive number.
            fileTarget.ArchiveFileName =
                string.Format("{0}/{1}.{2}.{{#}}.log", logPath, appName, suffix);
            // Disable concurrent writes because we always use a unique file for each process.
            fileTarget.ConcurrentWrites = false;
            return(fileTarget);
        }