Skip to content

not an issue, but this logger is not thread safe. #7

Description

@xklake

if you want to use it in mult-thread, you need make some change on code. i made a little change in publish function in FileLoggerHandler.cs
private static ReaderWriterLockSlim _readWriteLock = new ReaderWriterLockSlim();

        _readWriteLock.EnterWriteLock();
        StreamWriter writer = null;

        try
        {
            // Append text to the file
            writer = new StreamWriter(File.Open(Path.Combine(_directory, _fileName), FileMode.Append)); 
            writer.WriteLine(_loggerFormatter.ApplyFormat(logMessage));
            writer.Close();
        }
        finally
        {
            // Release lock
            if(writer != null)
            {
                writer.Close();
            }

        }
        _readWriteLock.ExitWriteLock();

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions